LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Display only:




CSS
/*
ignore this. it's just used to put the two example panels next to each other.
*/
  .part {
    float:left;
    margin:0 5px;
  }

/*
start by styling the box around the star.
the only important parts are display and width, which force the container to constrain to the star widths. Note that using padding is problematic and unadvised.
*/
  .stars {
		display:inline-block;
		width:auto;
		position:relative;
		font-size:28px;
		border:2px outset #FC0;
		border-radius:5px;
		background-color:navy;
    	margin:5px;
	}
/*
the BEFORE:pseudo element. This will represent the number of stars in the actual rating.
it floats above the AFTER element.
*/
	.stars:BEFORE {
		content:"★★★★★";
		position:absolute;
		overflow:hidden;
		z-index:1;
		left:0px;
		top:0px;
    /* everything below here is optional. */
		color:#FC0;
		text-shadow:0px 1px 0 #000, 0 -1px 0 #fff;
	}
/*
the AFTER:pseudo element. This will represent the total possible  stars available. It is set to relative to ensure it takes up the proper amount of space.
*/
	.stars:AFTER {
		content:"★★★★★";
		position:relative;
		color:#fff;
	}
/*
if including user rating controls, float the AFTER element.
*/
	.stars.rate:AFTER {
		position:absolute;
		left:0px;
	}
/*
default state for the  user rating controls. invisible, but floating above the BEFORE and AFTER elements
*/
	.stars.rate > A {
		color:transparent;
		text-decoration:none;
		position:relative;
		z-index:2;
	}
/*
if the user is floating thier mouse above the rating, hide the display stars.
*/
	.stars.rate:HOVER:BEFORE,
	.stars.rate:HOVER:AFTER {
		display:none;
	}
/*
turn all sthe start "ON" by default.
*/
	.stars.rate:HOVER > A {
		color:#FC0;
		text-shadow:0px 1px 0 #000, 0 -1px 0 #fff;
	}
/*
optional style for the specific star control a user is directly above.
*/
  .stars.rate:HOVER > A:HOVER {
		color:#FC0;
		text-shadow:0px 2px 0 #000, 0 -1px 0 #fff;
		top:-1px;
	}
/*
turn "OFF" all stars after the one the user is hovering over.
*/
	.stars.rate >A:HOVER ~ A {
		color:#fff;
		text-shadow:none;
	}
/* 
  all the styles below are used to display the apropriate portion of the BEFORE element based on percentage rating. unfortunately you will need to create a specific rule for each level of granularity you wish to display.


  if the CSS3 attr() function proposal ever gets implimented
  the remaining rules could all be replaced with the following:
  .stars[data-percent]:BEFORE {
    width:attr(data-percent,%,0);
  }
  
*/
	.stars:NOT([data-percent]):BEFORE,
  .stars[data-percent="0"]:BEFORE {
		display:none;
	}
/* 1/2 a star */
	.stars[data-percent="10"]:BEFORE {
		width:10%;
	}
/* 1 star */
	.stars[data-percent="20"]:BEFORE {
		width:20%;
	}
/* 1 & 1/2 stars */
	.stars[data-percent="30"]:BEFORE {
		width:30%;
	}
/* etc. */
	.stars[data-percent="40"]:BEFORE {
		width:40%;
	}
	.stars[data-percent="50"]:BEFORE {
		width:50%;
	}
	.stars[data-percent="60"]:BEFORE {
		width:60%;
	}
	.stars[data-percent="70"]:BEFORE {
		width:70%;
	}
	.stars[data-percent="80"]:BEFORE {
		width:80%;
	}
	.stars[data-percent="90"]:BEFORE {
		width:90%;
	}
	.stars[data-percent="100"]:BEFORE {
		width:100%;
	}

Description

A no-image, no JavaScript star rating widget with minimal HTML. Comes in two flavours; one for displaying a star rating, and one for both displaying and allowing users to set ratings.
Term
Mon, 11/27/2017 - 21:25

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv