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.

            
              <article>
    <section>
        <h1>Quantity Query SCSS Mixin <span>v.1.1</span></h1>
        <p>A quantity query is a complex CSS selector that allows styles to be applied to elements based on the number of siblings.</p>
        <p>For an in-depth explanation please read this excelent <a href="//alistapart.com/article/quantity-queries-for-css" target="_blank">article</a> by <a href="//codepen.io/heydon/" target="_blank">Heydon Pickering</a>.  
    </section>
    
    <section>
        <h2>Example</h2>
        <figure>
            <figcaption>3 or more items<br></figcaption>
            <ol class="example-from">
                <li></li>
                <li></li>                
                <li></li>                
            </ol>
            <button class="example-from-add">Add item</button>
            <button class="example-from-del">Remove item</button>                
        </figure>
    
        <figure>
            <figcaption>5 or less items</figcaption>
            <ol class="example-to">
                <li></li>
                <li></li>
                <li></li>
            </ol>
            <button class="example-to-add">Add item</button>
            <button class="example-to-del">Remove item</button>                
            
        </figure>
            
        <figure>
            <figcaption>Between 3 and 5 items</figcaption>
            <ol class="example-from-to">
                <li></li>
                <li></li>
                <li></li>
            </ol>
            <button class="example-from-to-add">Add item</button>
            <button class="example-from-to-del">Remove item</button>                
        </figure>
        
        <figure>
            <figcaption>Exactly 3 items</figcaption>
            <ol class="example-exactly">
                <li></li>
                <li></li>
                <li></li>
            </ol>
            <button class="example-exactly-add">Add item</button>
            <button class="example-exactly-del">Remove item</button>                
        </figure>        
                    
            
    </section>
    
    
    <!-- section>
<fieldset>
    <h2>Try it out (add as external pen resource)</a>
  <label>
    <ol><li>copy link below </li><li>open css settings (gear icon)</li><li>paste in add external css</li></ol>
    <input value="//codepen.io/jakob-e/pen/woGXWe.scss" style="font-size:20px;width:calc(100% - 20px); padding:10px;" onfocus="this.setSelectionRange(0, this.value.length)"/>
  </label>
</fieldset>          
    </section-->
    
    
<section>
    <h2>Use it</h2><code data-ace-theme="tomorrow" data-ace-mode="scss" data-ace-cursor="false">ol li { 
    @include qq(from 3)     { /* styling if the list has 3 or more items */ }
    @include qq(to 5)       { /* styling if the list has 5 or less items */ }
    @include qq(from 3 to 5){ /* styling if the list has between 3 and 5 items */ }
    @include qq(equal 4)    { /* styling if the list has exactly 4 items */ }    
}

// Multiple selectors works too
ol, ul.foo { 
    li { @include qq(from 3){ /* ... */ } }
}</code>
    </section>
    <section>
        <h2>The Mixin</h2><code data-ace-theme="tomorrow" data-ace-mode="scss" data-ace-cursor="false">//  ·············································································
//
//  Quantity Query 
//
//        
//  ol li {         
//          
//    @include qq(min 3)         { /* styling if the list has 3 or more items */ }        
//    @include qq(from 3)        { /* styling if the list has 3 or more items */ }         
//    @include qq(at least  3)   { /* styling if the list has 3 or more items */ }         
//
//    @include qq(max 5)         { /* styling if the list has 5 or less items */ }        
//    @include qq(max 5)         { /* styling if the list has 5 or less items */ }        
//    @include qq(at most  5)    { /* styling if the list has 5 or less items */ }        
//        
//    @include qq(equal 4)       { /* styling if the list has exactly 4 items */ }        
//    @include qq(exactly 4)     { /* styling if the list has exactly 4 items */ }        
//
//    @include qq(min 3 max 5)            { /* styling if the list has between 3 and 5 items */ }        
//    @include qq(from 3 to 5)            { /* styling if the list has between 3 and 5 items */ }         
//    @include qq(at least  3 at most 5)  { /* styling if the list has between 3 and 5 items */ }  
//
//  }
//  ·············································································  
@mixin qq($query){
  $equal:  index-some($query, equal, exactly);
  $min: index-some($query, min, least, from) or $equal;
  $min: if($min, nth($query, $min + 1), null); 
  $max: index-some($query, max, most, to) or $equal;
  $max: if($max, nth($query, $max + 1), null); 

  $list:();
  $last: null;
  //  loop through selectors to find the last selector of each part
  //  the "alphabet" loop is just a simple way to listify selectors
  //  (if the selector has more than 26 parts – you're on your own)
  @each $selector in & {
    @each $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z in $selector {
      $list: append($list, $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z);
    }
    $last: nth($list, length($list));
  }

  @if $min and $max {
    &:nth-last-child(n+#{$min}):nth-last-child(-n+#{$max}):first-child, 
    &:nth-last-child(n+#{$min}):nth-last-child(-n+#{$max}):first-child ~ #{$last} { @content; }        
  }
  @else if $min {
    &:nth-last-child(n+#{$min}), 
    &:nth-last-child(n+#{$min}) ~ #{$last} { @content; }    
  }
  @else if $max {
    &:nth-last-child(-n+#{$max}):first-child, 
    &:nth-last-child(-n+#{$max}):first-child ~ #{$last} { @content; }     
  }
}
//  helper function to return the first found list index
//  of a number of values passed
@function index-some($list, $values...){
  @each $value in $values { @if index($list, $value){ @return index($list, $value); } }
  @return null;
}</code>
    </section>
<article>


<footer data-related-pens=""></footer>      
            
          
!
            
              //  ·············································································
//
//  Quantity Query 
//
//        
//  ol li {         
//          
//    @include qq(min 3)         { /* styling if the list has 3 or more items */ }        
//    @include qq(from 3)        { /* styling if the list has 3 or more items */ }         
//    @include qq(at least  3)   { /* styling if the list has 3 or more items */ }         
//
//    @include qq(max 5)         { /* styling if the list has 5 or less items */ }        
//    @include qq(max 5)         { /* styling if the list has 5 or less items */ }        
//    @include qq(at most  5)    { /* styling if the list has 5 or less items */ }        
//        
//    @include qq(equal 4)       { /* styling if the list has exactly 4 items */ }        
//    @include qq(exactly 4)     { /* styling if the list has exactly 4 items */ }        
//
//    @include qq(min 3 max 5)            { /* styling if the list has between 3 and 5 items */ }        
//    @include qq(from 3 to 5)            { /* styling if the list has between 3 and 5 items */ }         
//    @include qq(at least  3 at most 5)  { /* styling if the list has between 3 and 5 items */ }  
//
//  }
//  ·············································································  
@mixin qq($query){
  $eq:  index-some($query, equal, exactly);
  $min: index-some($query, min, least, from) or $eq;
  $min: if($min, nth($query, $min + 1), null); 
  $max: index-some($query, max, most, to) or $eq;
  $max: if($max, nth($query, $max + 1), null); 

  $list:();
  $last: null;
  //  loop through selectors to find the last selector of each part
  //  the "alphabet" loop is just a simple way to listify selectors
  //  (if the selector has more than 26 parts – you're on your own)
  @each $selector in & {
    @each $a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k, $l, $m, $n, $o, $p, $q, $r, $s, $t, $u, $v, $w, $x, $y, $z in $selector {
      $list: append($list, $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z);
    }
    $last: nth($list, length($list));
  }

  @if $min and $max {
    &:nth-last-child(n+#{$min}):nth-last-child(-n+#{$max}):first-child, 
    &:nth-last-child(n+#{$min}):nth-last-child(-n+#{$max}):first-child ~ #{$last} { @content; }        
  }
  @else if $min {
    &:nth-last-child(n+#{$min}), 
    &:nth-last-child(n+#{$min}) ~ #{$last} { @content; }    
  }
  @else if $max {
    &:nth-last-child(-n+#{$max}):first-child, 
    &:nth-last-child(-n+#{$max}):first-child ~ #{$last} { @content; }     
  }
}
//  helper function to return the first found list index
//  of a number of values passed
@function index-some($list, $values...){
  @each $value in $values { @if index($list, $value){ @return index($list, $value); } }
  @return null;
}




//     just some crappy styling 
$color: rebeccapurple;


html {
  box-sizing: border-box;
}

*, *:after, *:before {
  box-sizing: inherit;
}
fieldset  { border:0; }
article {
  max-width: 860px;
  margin: 0 auto;
  background: white;
}

h1 {
  font: 300 40px Lato, sans-serif;
  color: $color;
}

h1 span {
  font-size: 12px;
  position: absolute;
}

h2 {
  font: 400 18px Lato, sans-serif;
  color: $color;
}

p strong {
  font-weight: 700;
}

p, li, a {
  font: 400 16px Lato, sans-serif;
  color: #333;
  max-width: 600px;
}

h1 {
  display: inline-block;
  position: relative;
}

a {
  color: $color;
  text-decoration: none;
}
a:hover {
  background-color: $color;
  color: #fff;
  outline: 2px solid $color;
}

span {
  color: #999;
}

article, section, header, code {
  display: block;
}

article {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 20px 100px;
}

code {
  margin: 20px 0;
  font-family: monospace;
}

code * {
  font-size: 10px;
}

input {
  width: 100%;
  font-size: 16px;
  padding: 10px;
  margin: 20px 0 0;
  background: whitesmoke;
  border: 1px solid #ccc;
  border-radius: 5px;
  outline: 0;
}

.small {
  font-size: 12px;
}

ul {
  margin: 0;
  padding-left: 20px;
  padding-bottom: 20px;
}

li {
  max-width: 520px;
  margin-bottom: 8px;
}

.note {
  padding: 10px 20px;
  background: whitesmoke;
  border-radius: 5px;
  margin-bottom: 20px;
}


section:after{content:'';display:table;clear:both;}
fieldset {border:0;}
input { outline: 0; }
input::-moz-selection { background: $color;color:white; }
input::selection { background: $color;color:white; }  


























button { 
    display: inline-block; appearance:none; background: rgba(0, 0, 0, 0.2); color:white; border:0; margin:10px; padding:5px;
   font: 400 12px Lato, sans-serif;  width: calc(50% - 40px); 
    text-align:center;
    outline:0;
    transition: all 0.5s;
    border-radius:5px; cursor: pointer;
    &:hover { background: rgba(0, 0, 0, 0.5); }
}

figure {
    text-align: center;
    display:block;
    width:31%;
    width:23%;
    float:left; margin:1%; padding:0;
    background: whitesmoke; 
    border-radius: 5px;
    
    @media (max-width: 640px){ width: 100%;}
}

figcaption {  
    font: 400 16px Lato, sans-serif;
    color:$color; 
    text-align: center; 
    padding:10px;
}
li { margin-right:30px; &:before { display:block; padding: 4%; font-size:12px; }}
.example-from li { 
    @include qq(to 2) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }}    
    @include qq(from 3) { background-color: lighten($color,20%);; &:before { color: white; content: 'condition is true' }}
}
.example-to li { 
    @include qq(from 6) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }} 
    @include qq(to 5) { background-color: lighten($color,20%); &:before { color: white; content: 'condition is true' }}
}
.example-from-to li { 
    @include qq(to 2) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }}       
    @include qq(from 6) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }}     
    @include qq(from 3 to 5) { background-color: lighten($color,20%);;  &:before { color: white;  content: 'condition is true' }}
}

.example-exactly li { 
    @include qq(to 2) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }}       
    @include qq(from 4) { background-color: lighten($color,50%); &:before { color:$color; content: 'condition is false' }}     
    @include qq(equal 3) { background-color: lighten($color,20%);;  &:before { color: white;  content: 'condition is true' }}
}




[data-related-pens] a { border:0; outline:0; width:18% !important; font-size:12px !important; }





            
          
!
            
              //
// Editor: //cdnjs.cloudflare.com/ajax/libs/ace/1.1.3/ace.js
var theme='ace/theme/tomorrow';
var mode='ace/mode/scss';
$('code').each(function(){
var editor= ace.edit(this);  
    editor.setTheme('ace/theme/'+$(this).attr('data-ace-theme'));
    editor.getSession().setMode('ace/mode/'+$(this).attr('data-ace-mode'));
    editor.renderer.setShowGutter(false); 
    editor.setShowPrintMargin(false);
    editor.setShowPrintMargin(false);
    editor.setDisplayIndentGuides(false);
    
    editor.setOptions({ 
      maxLines: Infinity, 
      //readOnly: false,
      highlightActiveLine: false,
      highlightGutterLine: false      
    });
    if($(this).attr('data-ace-cursor')==='false'){
      $('.ace_hidden-cursors').hide();
    }
    // https://ace.c9.io/api/virtual_renderer.html
    // 
});

// Select on click
$("input[type='text']").on('click',function () { $(this).select(); });



$('.example-from-add').on('click',function(){ $('.example-from').append('<li/>')})
$('.example-from-del').on('click',function(){ $('.example-from li:last-child ').remove()})
$('.example-to-add').on('click',function(){ $('.example-to').append('<li/>')})
$('.example-to-del').on('click',function(){ $('.example-to li:last-child ').remove()})
$('.example-from-to-add').on('click',function(){ $('.example-from-to').append('<li/>')})
$('.example-from-to-del').on('click',function(){ $('.example-from-to li:last-child ').remove()})
$('.example-exactly-add').on('click',function(){ $('.example-exactly').append('<li/>')})
$('.example-exactly-del').on('click',function(){ $('.example-exactly li:last-child ').remove()})
            
          
!
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