Columns with Ordered Lists

I have a dynamically created ordered list that is split into two columns. The problem is that when I have an odd number of list items, the last item of the first column is split between the two columns.

I would like to fix this with just html/css if possible. I know what I could do if I resorted to php or js.

I have hunted and found a fix for unordered lists which use display: inline-block, and width: 100% on the list items, but it makes the bullets disappear. The solution for that, apparently, is to use content with a bullet symbol. This works because all the list items have the same bullet. This will not work with ordered lists.

Is there anyway to get the numbers of the list items to re-appear using just css?

Here is my demo code:

<!DOCTYPE html>

<html lang="en" class="no-js">
<head>
    <meta charset = "utf-8"> 
    <title></title>
    <meta name="description" content="">
    
    <link rel="stylesheet" href="style.css">

      <!--[if lt IE 9]>
      <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
      <![endif]-->
</head>

<body>

<div id = "wrapper">
    <h1>Ordered Lists in Columns</h1>
    <div  id="even">
        <h2>Even Number of List Items</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
    <div  id="odd">
        <h2>Odd Number of List Items</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
    <div  id="odd-fix">
        <h2>Odd Number of List Items with Fix</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
</div><!-- end of #wrapper -->

</body>

</html>

and:

* {
    margin: 0;
    padding: 0;
}

#wrapper {
    width: 900px;
    margin: 0 auto;
    padding: 30px;
    border: 1px solid blue;
}

h1, h2 {
    margin: 0 0 30px 0;
}

ol {
    margin: 0 0 30px 20px;
    columns: 2;
    -webkit-columns: 2;
    -moz-columns: 2;
    column-gap: 30px;
    -webkit-column-gap: 30px;
    -moz-column-gap: 30px;
}

ol li {
    margin: 0 0 10px 0;
}

#odd-fix ol li {
    display: inline-block;
    width: 100%;
}

All of this could be avoided if you simply set the page-break to not break halfway.

ol li {
    margin: 0 0 10px 0;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
}

You can remove that inline-block/width:100% “fix”.

This might work for you too if I understand what you’re trying to do correctly.

http://codepen.io/ChrisofArabia/pen/RNORZx

My solution also forgot the numbering issue which can be fixed by a simple counter increment in CSS

<!DOCTYPE html>

<html lang="en" class="no-js">
<head>
    <meta charset = "utf-8"> 
    <title></title>
    <meta name="description" content="">
    <style>
	* {
    margin: 0;
    padding: 0;
}

#wrapper {
    width: 900px;
    margin: 0 auto;
    padding: 30px;
    border: 1px solid blue;
}

h1, h2 {
    margin: 0 0 30px 0;
}

ol {
    margin: 0 0 30px 20px;
    columns: 2;
    -webkit-columns: 2;
    -moz-columns: 2;
    column-gap: 30px;
    -webkit-column-gap: 30px;
    -moz-column-gap: 30px;
	counter-reset: colnum;
}
ol li {
    margin: 0 0 10px 0;
	overflow:hidden;
	-webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
	counter-increment: colnum;
	
}
ol li:before {
    content: counter(colnum)": ";
	float:left;
}


</style>
</head>

<body>

<div id = "wrapper">
    <h1>Ordered Lists in Columns</h1>
    <div  id="even">
        <h2>Even Number of List Items</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
    <div  id="odd">
        <h2>Odd Number of List Items</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
    <div  id="odd-fix">
        <h2>Odd Number of List Items with Fix</h2>
        <ol>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
            <li>
                <h3>List Item Heading</h3>
                <p>List item content goes here.</p>
            </li>
        </ol>
    </div>    
</div><!-- end of #wrapper -->

</body>

</html>

@chrisofarabia, my issue was with part of a list item being split between the two columns, instead of keeping the list item as one block.

Okay, that worked and also did not interfere with the counters. You do not need to include the counter resets at all. Thank you. I did not know about those column properties. Thank you.

ol li {
    margin: 0 0 10px 0;
    -webkit-column-break-inside: avoid;
    page-break-inside: avoid;
    break-inside: avoid;
}

seemed to be all that I needed.

Not too many people use it since CSS3 columns aren’t used all that often from what I see . Glad it was helpful. I thought you had two issues; one being the breaking, and the other being the numbering not being used since you were using CSS3 columns. Apologies.

The numbering showed up fine until I used display: inline-block for the list items. Something to add to my “must-remember-for-next-time” list.

CSS3 columns will also remove the numbering as well. I’m guessing you added both at the same time.

http://codepen.io/ryanreese09/pen/YPmVeB

Actually, they don’t. See my demo for unordered lists. I use columns and column-gap with no problems with the numbering.

I’m confused. No numbers are showing up for your demo.

My demo was based off your demo, minus aesthetic crap like margins and font sizes.

Are we talking about two separate issues?

I’m talking about <ol>s normally adding 1/2/3/4/5(etc) to their <li>'s since it is an ORDERED list (numbers).

I then say CSS3 columns does not allow the numbering to take place. If you go into my codepen demo and remove the CSS3 column code from ol{} you will see the numbers reappear.

That is what I"m saying. IF I understand you right, you are saying you somehow have numbers…?

Here is a screenshot of my demo in Firefox (I used the fix you suggested for the third ordered list). The other two ordered lists are unchanged. All of them are showing the numbers.

By the way, that other CSS is not aesthetic ‘crap’. I happen to like the results of my coding (front- and back-end) to look half-decent when I am building something. It just happens to be part of my particullar workflow - not crap.

You misunderstood my use of the word “crap” to be insulting. That was not the case. No need to be insulted. I was merely referencing the other code that wasn’t necessary to the demo.

And I was on Chrome. Looks like FIrefox is keeping the numbering but Chrome isn’t. You should add my code in and eliminate the default <ol> behavior since Chrome is handling the numbering differently than FF.

Thanks. This is just for some local development tools that I am building for myself, and I use Firefox so that fix won’t be necessary, but I will keep that in mind if I ever use it on a client project.

No offense taken.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.