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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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="page-wrap">
  <div class="intro">
    <h1>Super Duper Expressive Color Attributes</h1>
    <p>Styling elements with <code class="bg">data-*</code> and way too many <code class="bg">~=</code> selectors. NSFProd.</p>
    <p class="answering-the-obvious"><strong>Q:</strong> But isn't this just a terrible idea?<br>
      <strong>A:</strong> ✋ Swerve.</p>
  </div>

  <div class="color-stuff">
    <div class="color">
      <div class="box" data-color="crimson"></div>
      <div class="descriptor"
           ><code><b>data-color</b> = <i>"crimson"</i></code></div>
    </div>
    <div class="color">
      <div class="box" data-color="blueish crimson"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"blueish crimson"</i></code>
      </div>
    </div>
    <div class="color">
      <div class="box" data-color="crimsonish blueish"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"crimsonish blueish"</i></code>
      </div>
    </div>
    <div class="color">
      <div class="box" data-color="crimsonish blue"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"crimsonish blue"</i></code>
      </div>
    </div>
    <div class="color">
      <div class="box" data-color="greenish cyanish"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"greenish cyanish"</i></code>
      </div>
    </div>
    <div class="color">
      <div class="box" data-color="greenish cyanish but not that green"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"greenish cyanish but not that green"</i></code>
      </div>
    </div>
    <div class="color">
      <div class="box" data-color="tomatoish pinkish but mostly tomato"></div>
      <div class="descriptor">
        <code><b>data-color</b> = <i>"tomatoish pinkish but mostly tomato"</i></code>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                // could of course add way more colors. I had all of the named colors to begin with but the SCSS processing was timing out and this is more than enough for a demo.
$colors: (crimson, red, pink, tomato, orange, yellow, purple, green, cyan, blue, brown, white, beige, silver, gray, black, magenta);

$length: length($colors);
@for $i from 1 to $length {
  [data-color~="#{nth($colors, $i)}"] {
    background: nth($colors, $i);
  }
  @for $j from ($i+1) through $length {
    
    // color 1 == color 2
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}ish"],
    [data-color~="#{nth($colors, $i)}"][data-color~="#{nth($colors, $j)}"]{
      background: mix(nth($colors, $i), nth($colors, $j));
    }
    
    // color 1 < color 2
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}ish"][data-color~="not"][data-color~="#{nth($colors, $i)}"],
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}ish"][data-color~="mostly"][data-color~="#{nth($colors, $j)}"],
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}"] {
      background: mix(nth($colors, $i), nth($colors, $j), 25%);
    }
    
    // color 1 > color 2
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}ish"][data-color~="not"][data-color~="#{nth($colors, $j)}"],
    [data-color~="#{nth($colors, $i)}ish"][data-color~="#{nth($colors, $j)}ish"][data-color~="mostly"][data-color~="#{nth($colors, $i)}"],
    [data-color~="#{nth($colors, $i)}"][data-color~="#{nth($colors, $j)}ish"] {
      background: mix(nth($colors, $i), nth($colors, $j), 75%);
    }
  }
}

// the last color is missed by the loops :(
[data-color~="#{nth($colors, $length)}"] {
  background: nth($colors, $length);
}

body {
  font-family: "Open Sans";
  color: #333;
  display: flex;
  background:  #ecf2f5;
}

.page-wrap {
  margin: 0 auto;
}

h1 {
  font-family: "Work Sans";
  margin-top: 40px;
  margin-bottom: 24px;
  color: #444;
}
code {
  font-family: "Space Mono";
  &.bg {
    background: #d3e3ea;
  }
  padding: 0 4px;
  border-radius: 2px;
  white-space: nowrap;
}

.intro {
  text-align: center;
  &:after {
    content: "";
    display: block;
    width: 128px;
    height: 3px;
    background: crimson;
    margin: 32px auto ;
  }
}

.color {
  display: flex;
  margin-bottom: 16px;
  &:last-of-type {
    margin-bottom: 40px;
  }
}

.box {
  height: 56px;
  width: 56px;
  float:left;
  margin-right: 16px;
  border-radius: 4px;
  box-shadow: 0 16px 24px -8px rgba(0, 0, 0, .1);
}

.descriptor {
  background: none;
  margin: auto 0;
}

.answering-the-obvious {
   &:before {
    content: "";
    display: block;
    width: 40px;
    height: 3px;
    background: #dfdfdf;
    margin: 24px auto ;
  }
}

.attr {
  color: crimson;
}
              
            
!

JS

              
                
              
            
!
999px

Console