9

Consider the following markup with Boostrap 3:

<ol>
    <li>
        <div class="row">
            <div class="col-xs-6">
                Row 1, col 1
            </div>
            <div class="col-xs-6">
                Row 1, col 2
            </div>
        </div>
    </li>
</ol>

Why does the text not align with the "1." from the <ol>? See http://jsfiddle.net/R2tXU/ as an example...

Also, would it be valid to put the class="row" right on the <li>?

Thanks!

1
  • I'm stumped! I put the row on an li inside a ul and I didn't see any problems in my code, but with the ol the numbers sure do get all messed up. Commented Jul 24, 2014 at 21:06

2 Answers 2

8

Sorry, I'm a little late responding here... However, using valid markup is important and therefore I think it's worth mentioning alternative solutions...

Option 1

Using a little HTML and CSS, you could set the value on each li ([ Valid HTML5 ]):

[ JS Fiddle Example ]

HTML

<ol>
    <li class="col-xs-6" value="1">Row 1, col 1</li>
    <li class="col-xs-6">Row 1, col 2</li>
    <li class="col-xs-6" value="2">Row 2, col 1</li>
    <li class="col-xs-6">Row 2, col 2</li>
</ol>

CSS

ol li:nth-child(2n+0) {
    list-style: none;
}

Option 2

However, if you're going for a purely CSS approach, this is probably the best option...

[ JSFiddle Example ]

HTML

<ol>
    <li class="col-xs-6">Row 1, col 1</li>
    <li class="col-xs-6">Row 1, col 2</li>
    <li class="col-xs-6">Row 2, col 1</li>
    <li class="col-xs-6">Row 2, col 2</li>
</ol>

CSS

ol {
    counter-reset: index;
}

ol li:nth-child(2n+0) {
    counter-increment: index;
    list-style: none;
}

ol li:nth-child(2n+0):before {
    content: counter(index) ".";
}

ol li:nth-child(2n+0):before {
    content: "";
}

However, do keep in mind [ browser compatibility ].

Sign up to request clarification or add additional context in comments.

1 Comment

Any thoughts on how to make this work with portlets? The background color doesn't fill to the bottom of the portlet when using this method. Edit: Never mind, just wrap it in a DIV with row class.
3

This is how I fixed it. No other additional styles, only Bootstrap classes.

You just need to add these class to row div d-inline-flex w-100

 <ol>
    <li>
        <div class="row d-inline-flex w-100 ml-2">
            <div class="col-xs-6">
                Row 1, col 1
            </div>
            <div class="col-xs-6">
                Row 1, col 2
            </div>
        </div>
    </li>
    <li>
        <div class="row d-inline-flex w-100 ml-2">
            <div class="col-xs-6">
                Row 2, col 1
            </div>
            <div class="col-xs-6">
                Row 2, col 2
            </div>
        </div>
    </li>
</ol>

Fiddle here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.