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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>Demo of CSS Quantity selector</h1>

<p>
  Demonstration of querying and setting responsive styles to navigation with <strong>exactly 4 items</strong> and <strong>5 or more items</strong>. The <em>font-size is smaller</em> when there are more items in the navigation.
  The grey border simulates the website shown in narrow width screen.
  Original idea from <a href='http://alistapart.com/article/quantity-queries-for-css'>A List Apart—Quantity Queries for CSS</a>.
</p>

<div class='mock-website-container'>
  <h2>Nav with 2 items. (normal)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
    </ul>
  </nav>
</div>

<div class='mock-website-container'>
  <h2>Nav with 3 items (normal)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
      <li>Link C</li>
    </ul>
  </nav>
</div>

<div class='mock-website-container'>
  <h2>Nav with 4 items (90%)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
      <li>Link C</li>
      <li>Link D</li>
    </ul>
  </nav>
</div>

<div class='mock-website-container'>
  <h2>Nav with 5 items (70%)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
      <li>Link C</li>
      <li>Link D</li>
      <li>Link E</li>
    </ul>
  </nav>
</div>

<div class='mock-website-container'>
  <h2>Nav with many items (70%)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
      <li>Link C</li>
      <li>Link D</li>
      <li>Link E</li>
      <li>Link F</li>
    </ul>
  </nav>
</div>

<div class='mock-website-container'>
  <h2>Nav with many items (70%)</h2>
  <nav>
    <ul>
      <li>Link A</li>
      <li>Link B</li>
      <li>Link C</li>
      <li>Link D</li>
      <li>Link E</li>
      <li>Link F</li>
      <li>Link G</li>
      <li>Link H</li>
    </ul>
  </nav>
</div>

              
            
!

CSS

              
                /* Quantity selector */
/* Exactly 4 items*/
nav li:nth-last-child(4):first-child,
nav li:nth-last-child(4):first-child ~ li {
  font-size: 90%;
}

/* More than 4 items (5+ items) */
nav li:nth-last-child(n+5):first-child,
nav li:nth-last-child(n+5):first-child ~ li {
  font-size: 70%;
  
  /* Smaller button */
  padding-left: 8px;
  padding-right: 8px;
}

/* Nav list styles */
nav {
  font-size: 16pt; /* Default nav link font size, to be overridden by quantity selector. */
}
nav ul {
  margin: 0;
/*   margin-right: -13px; */
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
}
nav li {
  text-align: center;
  margin-bottom: 8px;
  margin-right: 10px;  
  padding: 6px 12px;
  background: GOLD;  
  color: #222;
  border-radius: 3px;
  cursor: pointer;
}
nav li:last-child {
  margin-right: 0;
}
nav li:hover {
  background: YELLOW;
}

/* Not our focus */
* {
  box-sizing: border-box;
}
body {
  padding: 80px;  
}

.mock-website-container {
  width: 375px;
  border: 1px solid LIGHTGREY;
  margin: 20px 0;
  padding: 10px;
  font-size: 12pt;
  border-radius: 3px;
}

.mock-website-container h1,
.mock-website-container h2 {
  font-size: 100%;
}
              
            
!

JS

              
                
              
            
!
999px

Console