123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <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>
            
          
!
            
              // 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;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console