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

              
                <h1><a href="https://github.com/stowball/Suzi" target="_blank">Suzi's</a> Poor man's nth-child Sass mixin</h1>
<p>As LT IE 9 doesn't support nth-child (and Selectivzr kills SharePoint), I've written a Sass mixin to achieve the "<a href="http://abouthalf.com/development/poor-mans-nth-child-selector-for-ie-7-and-8/">Poor Man's nth-child</a>".</p>
<p>It supports single (X), repeating (Xn), repeating starting from an index (Xn+Y / Xn-Y) and odd &amp; even.</p>
<p>It takes the following parameters:</p>
<ol>
  <li>$an - the counting method, eg: 2n, 3n, odd - default is 2n</li>
  <li>$an can also be a list, with the 2nd parameter being the modifier, eg: 2 for ($an+2) or -3 for ($an-3)</li>
  <li>$sibling - the sibling element selector, eg: 'li', 'div' - default is '*'</li>
  <li>$count - how many sibling selectors to support, eg: 10, 20 - default is 15</li>
</ol>

<h2>nth-child(even)</h2>
<ul class="even"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(odd)</h2>
<ul class="odd"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(3n)</h2>
<ul class="x3n"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(3n+2)</h2>
<ul class="x3n2"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(3n-2)</h2>
<ul class="x3n-2"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(1n+4)</h2>
<ul class="x1n4"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>

<h2>nth-child(5)</h2>
<ul class="x5"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li><li>10</li></ul>
              
            
!

CSS

              
                @import "compass/css3";

@function strip-units($number) {
	@return $number / ($number * 0 + 1);
}

@mixin nth-child($an: 2n, $sibling: '*', $count: 15) {
	$index: '';
	$n: false;
	$selector: '';
	$modifier: 0;
	
	@if (type-of($an) == list) {
		$index: nth($an, 1);
		$modifier: nth($an, 2);
	}
	@else {
		$index: $an;
	}
	
	@if ($index == 'even' or $index == even) {
		$index: 2n;
	}
	
	@if ($index == 'odd' or $index == odd) {
		$index: 2n;
		$modifier: 1;
	}
	
	@if (unit($index) == 'n') {
		$index: strip-units($index);
		$n: true;
	}
	
	@if ($modifier < 0) {
		@if (abs($modifier) > $index){
			$modifier: -(abs($modifier) % floor($index));
		}
		$modifier: $modifier + floor($index);
	}
	
	@if ($index > 0) {	
		@if ($n == false) {
			$count: 1;
		}
		
		@if ($index == 1) {
			$selector: '&:first-child';
		}
		
		@if ($modifier > 1) {
			@for $j from 0 to $modifier - 1 {
				$selector: $selector + '+ ' + $sibling;
			}
			$selector: $selector + ',';
		}
		
		@for $i from 1 to $count + 1 {
			@if ($i > 1) {
				$selector: $selector + ', ';
			}
			@for $x from (1 - $modifier) to $index * $i {
				$selector: $selector + '+ ' + $sibling;
			}
		}
	}
	
	@if ($index > 0) {
		@if ($modifier == 1) {
			@content;
		}
		
		#{$selector} {
			@content;
		}
	}
}

body {
  padding: 0 1em;
}

ul {
	list-style: none;
	li {
		padding: 3px;
	}
}

.selected {
	background: #000;
	color: #fff;
}

.even > li:first-child {
	@include nth-child(even, 'li') {
		@extend .selected;
	}
}

.odd > li:first-child {
	@include nth-child(odd, 'li') {
		@extend .selected;
	}
}

.x3n > li:first-child {
	@include nth-child(3n, 'li') {
		@extend .selected;
	}
}

.x3n2 > li:first-child {
	@include nth-child((3n, 2), 'li') {
		@extend .selected;
	}
}

.x3n-2 > li:first-child {
	@include nth-child((3n, -2), 'li') {
		@extend .selected;
	}
}

.x1n4 > li {
	@include nth-child((1n, 4), 'li') {
		@extend .selected;
	}
}

.x5 > li:first-child {
	@include nth-child(5, 'li') {
		@extend .selected;
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console