startv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource
via CSS Lint

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource
via JS Hint

Code Indentation

     

Save Automatically?

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

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              <h1>Poor man’s nth-child</h1>
<p>Inspired by <a href="http://abouthalf.com/2011/07/06/poor-mans-nth-child-selector-for-ie-7-and-8/">http://abouthalf.com/2011/07/06/poor-mans-nth-child-selector-for-ie-7-and-8/</a></p>
<p>Just use the Sass function <code>#{nth-child(n)}</code> in your selectors to make nth-child work in IE7 and IE8</p>

<h3>li#{nth-child(3)}</h3>
<ul>
  <li>child 1</li>
  <li>child 2</li>
  <li>child 3</li>
  <li>child 4</li>
  <li>child 5</li>
</ul>

<h3>to do</h3>
<p>build in support for nth-child functoins like <code>nth-child(3n+3)</code>.</p>
            
          
!

CSS

            
              @import "compass/css3";

// inspired by:
// http://abouthalf.com/2011/07/06/poor-mans-nth-child-selector-for-ie-7-and-8/


// function
@function nth-child($n) {
  $nth-child: first-child;
  @for $i from 2 through $n {
    $nth-child: append($nth-child, #{"+ *"});
  }
  @return #{":"}$nth-child;
}


// call in nth-child this way instead of with :
li#{nth-child(3)} {
  color: red;
}
            
          
!

JS

            
              
            
          
!
999px
Loading ..................

Console