Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="part">
<p>Display only:</p>
<div class="stars" data-percent="10"></div><br>
<div class="stars" data-percent="40"></div><br>
<div class="stars" data-percent="90"></div><br>
</div>
<div class="part">
<p>With user interaction:</p>
<div class="stars rate" data-percent="30"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
<div class="stars rate" data-percent="50"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
<div class="stars rate" data-percent="80"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
</div>
              
            
!

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%;
	}

              
            
!

JS

              
                
              
            
!
999px

Console