css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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="article">
  <h1>Create sections with alternating backgrounds using <code>&lt;hr&gt;</code></h1>
  <hr>
  <p>Every time an <code>&lt;hr&gt;</code> element is added, the background alternates creating awesome sections.</p>
  <hr>
  <p>This could be used as an easy way to create sections without additional divs and markup in, say, a WordPress theme.</p>
  <hr>
  <p>This <del>does not work in any version of</del> now works in Internet Explorer 9+ and falls back nicely.</p>
  <hr>
  <h2>Here's an example of a section</h2>
  <p> A paragraph. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
  <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec sed odio dui. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Maecenas faucibus mollis interdum.</p>
  <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec sed odio dui. Maecenas sed diam eget risus varius blandit sit amet non magna. Vestibulum id ligula porta felis euismod semper.</p>
  <hr>
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/5247/city.jpg" alt="city" />
  <hr>
  <h2>Here's an example of another section</h2>
  <img class="align-left" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/5247/city.jpg" alt="city" />
  <p> A paragraph. Nullam id dolor id nibh ultricies vehicula ut id elit. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Nulla vitae elit libero, a pharetra augue. Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
  <p>Aenean lacinia bibendum nulla sed consectetur. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Sed posuere consectetur est at lobortis. Curabitur blandit tempus porttitor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.</p>
  <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Nulla vitae elit libero, a pharetra augue. Etiam porta sem malesuada magna mollis euismod. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Donec id elit non mi porta gravida at eget metus.</p>
  <select name="select">
    <option value="value1">Value 1</option> 
    <option value="value2" selected>Value 2</option>
    <option value="value3">Value 3</option>
    <option value="value1">Value 4</option> 
    <option value="value2">Value 5</option>
    <option value="value3">Value 6</option>
  </select>
  <hr>
  <h3>You're welcome.</h3>
</div>
            
          
!
            
              // Base styles (unimportant)
body {
  background: #7db1ff;
  color: #333;
  font: 18px/1.5 Helvetica, Arial, sans-serif;
}

.article {
  max-width: 560px;
  margin: 30px auto;
  padding: 30px 30px;
  box-sizing: border-box;
  overflow: hidden;

  
  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: -1;
  }
}

h1 {
  margin: 0;
  padding: 0;
  font-size: 24px;
  text-align: center;
}

p {
  margin: 0 0 1em;
}

img {
  display: block;
  max-width: 100%;
}

.align-left {
  float: left;
  max-width: 35%;
  margin: 0 30px 15px 0;
}

// The magic (separated for easy of understanding)
.article {
  position: relative;
  background: #ffffff; // fallback bg for IE 8
  background: none, none; // removes fallback on newer browsers
  
  // The background color cannot be set on article or section backgrounds will be covered. I'm using the :before pseudo element instead to acheive the same result.
  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: -1;
  }
}

hr {
  height: 0;
  margin: 30px -30px;
  border: 0;
  border-bottom: 1px solid #eee;
  position: relative;
  overflow: visible;

  // Also uses a pseudo element to set the background for each section.
  &:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 9999em;
    background: #fff;
    z-index: -1;
  }

  &:nth-of-type(odd){
    &:before {
      background: #fafafa;
    }
  }
}

            
          
!
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.
Loading ..................

Console