0

Below is the HTML code for two ordered list items. I need to insert an element with float: left into some of these list items. But this shifts the numbering to the right:

.blob {
    float: left;
    width: 1cm;
    height: 5mm;
    background-color: #f00;
}
<ol>
    <li>Item 1</li>
    <li><div class="blob"></div> Item 2</li>
</ol>

How can we avoid that? I prefer solutions without JavaScript.

To be clear: I want the numbers to be below each other and the red box left to the text of the second item.

Update: This issue only appears in Chrome.

theV0ID
  • 4,172
  • 9
  • 35
  • 56

1 Answers1

1

Don't use float, try display:inline-block instead.

Note: As mentioned by @HiddenHobbes in a comment

the [original] issue only appears to occur in Chrome.

.blob {
    display: inline-block;
    width: 1cm;
    height: 5mm;
    background-color: #f00;
}
<ol>
    <li>Item 1</li>
    <li><div class="blob"></div> Item 2</li>
</ol>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161