octocatstartv

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

            
              <h2>A vertically oriented ordered  list broken into 2 columns using CSS selectors</h2>
<a href="http://codepen.io/noahblon" title="Go to the Codepen profile of Noah Blon" rel="author">by Noah Blon</a>
<p>Since IE9 doesnt support CSS3 columns, or flexbox, here's an IE9+ method for creating a vertically oriented ordered list that breaks to two columns without needing extra elements, classes, or JS.</p>  
  
<h3>1<sup>st</sup>  Column contains more items if there are a total odd number of items</h3>

<ol class="roundDown">
  <li>Aloe</li>
  <li>Bergamot</li>
  <li>Calendula</li>
  <li>Damiana</li>
  <li>Elderflower</li>
  <li>Feverfew</li>
  <li>Ginger</li>
  <li>Hops</li>
  <li>Iris</li>
  <li>Juniper</li>
  <li>Kava kava</li>
  <li>Lavender</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
  <li>Pennyroyal</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
  <li>Pennyroyal</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
</ol>

<h3>2<sup>nd</sup> Column contains more items if there are a total odd number of items</h3>
<ol class="roundUp">
  <li>Aloe</li>
  <li>Bergamot</li>
  <li>Calendula</li>
  <li>Damiana</li>
  <li>Elderflower</li>
  <li>Feverfew</li>
  <li>Ginger</li>
  <li>Hops</li>
  <li>Iris</li>
  <li>Juniper</li>
  <li>Kava kava</li>
  <li>Lavender</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
  <li>Pennyroyal</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
  <li>Pennyroyal</li>
  <li>Marjoram</li>
  <li>Nutmeg</li>
  <li>Oregano</li>
</ol>

<h3> How it works</h3>
<p>All items are absolutely positioned based on the line height using nth-child.  The items in the second column are selected with nth-child using a clever trick to select half the items.  This overrides the initial absolute position styling.  The second columns is staticly positioned and pushed right with margin.   I've used Sass to make generating these rules easier but its not required. One caveat is that you'll need to know the maximum number of items that might be held in a single column.  It will work for any number of items below that value.  In addition, this positioning will only work with items that will fit on a single line.</p>

<h3>Additional Resources</h3>
<ul>
  <li><a href="http://alistapart.com/article/multicolumnlists" title="A list Apart article about multicol lists">Here's an old A List Apart article containing some other solutions which require specific classing</a></li>
  <li><a href=" http://codepen.io/keithclark/full/Hygkt" title="demo by Keith Clark" >An awesome and useful demo by Keith Clark with advanced CSS Selector usage</a></li>
</ul>
    
<footer>
  <a href="http://codepen.io/noahblon/details/Agpyc#comment-list">Thoughts? Comment on this Pen</a>
</footer>

            
          
!

CSS

            
              $max-column-items: 12; /* The maximum number of items a single column can handle.  If a column has more items than the maximum defined here, some items won't display. */
$line-height: 1.5; 
$list-font-size: 16px;

ol {
  position: relative;
  margin: 0 0 50px;
  padding: 0;
  font-size: $list-font-size;
}

ol li {
  position: absolute;
  margin: 0;
  padding: 0;
  width: 50%;
  background: #b3cae5;
  list-style-position: inside;
  line-height: $line-height;
}

@for $i from 2 through $max-column-items{
  ol li:nth-child(n+#{$i}){
    top: $line-height * ($i - 1) + em; /* line height is equal to the absolute position top for all items. will only effect first column because overridden later*/
  }
}

/* Round up puts more items in first column if odd total number of items 
*/
@for $i from 2 through $max-column-items {
  .roundUp li:nth-child(n+#{$i}):nth-last-child(-n+#{$i}) {
    position: static;
    margin-left: 50%;
    background: #efcab2;
  }
}

/* Round Down puts more items into second column if odd total number of items 
*/
@for $i from 2 through $max-column-items {
  .roundDown li:nth-child(n+#{$i + 1}):nth-last-child(-n+#{$i}) {
    position: static;
    margin-left: 50%;
    background: #efcab2;
  }
}

/* BASE STYLING */
body { padding: 3% 10%; font-size: 16px; font-family: Helvetica, Arial, sans-serif; }

footer { padding-top: 25px; border-top: 1px solid black; }
            
          
!

JS

            
              
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console