Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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="rating" data-rate="1">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="1.5">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="2">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="2.5">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="3">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="3.5">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating rating-4" data-rate="4">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="4.5">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
<div class="rating" data-rate="5">
  <i class="star-1">★</i>
  <i class="star-2">★</i>
  <i class="star-3">★</i>
  <i class="star-4">★</i>
  <i class="star-5">★</i>
</div>
              
            
!

CSS

              
                $font-size: 20px; // <-- Adjust this only!
$star-width: 1.5em;
$max-stars: 5;

body { 
  padding: 20px; 
  font-size: $font-size;
}

.rating {
  margin: 10px 0;
}

.rating i {
  display: inline-block;
  width: 0;
  height: $star-width;
  border-width: 0 ( $star-width / 2 );
  border-style: solid;
  border-color: #eee;
  border-radius: .22em;
  color: white;
  background: #eee;
  font-style: normal;
  line-height: $star-width + 0.1em;
  text-indent: -0.5em;
  text-shadow: 1px 0 1px hsl(0, 0%, 70%);
}


// Revamping the stars-color function
// To use a list and some logic
// In order to avoid repeted code
// Also add a fallback color, just in case (#333)
@function stars-color($stars) {
  @if type-of($stars) != number {
    @warn '#{$stars} is not a number for `stars-color`.';
    @return false;
  }
  
  $colors: #cc8b1f #dcb228 #f0991e #f26a2c #dd050b;
  @return if($stars <= length($colors), nth($colors, $stars), #333);
}

// Main loop, looping through 1 to 4 (instead of 5)
// 1. Instanciating a list that will be used as a CSS selector
// 2. Caching the return from stars-color to speed up compilation
@for $i from 1 to $max-stars {
  $selector: (); // 1
  $color: stars-color($i); // 2
  
  // Inner loop not dumping anything
  // 1. Only appending stuff to $selector
  // 2. Using the [attr^='X'] selector to target both X and X.Y
  // 3. Forcing comma separated list for the selector to work
  @for $j from 1 through $i {
    $selector: append(
      $selector, // 1
      unquote("[data-rate^='#{$i}'] .star-#{$j}"), // 2
      comma // 3
    );  
  }
  
  // Using the concatenated selector
  #{$selector} {
    border-color: $color;
    background: $color;
  }

  // For half ratings only, applying color to left border of next star
  [data-rate='#{$i + 0.5}'] .star-#{$i + 1} {
    border-left-color: $color;
  }
}

// Dealing with 5-stars rating in a very simple way
// Since there is no 5.5 rating possible
$color: stars-color($max-stars);
[data-rate='#{$max-stars}'] i {
  border-color: $color;
  background: $color;
}


/** Print */

@media print {
  .rating {
    -webkit-print-color-adjust: exact;
    i {
      text-shadow: none;
    }
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console