List item bullets do not align properly to the right of a left floating div. The minimal code goes like this:
<div style="float:left; background-color:red;width:100px;">aa<br>bb<br>cc<br>dd</div>
<p>Title</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
https://jsfiddle.net/Lg73hzfa/
Some suggestions from other posts and their drawbacks:
- Set
<ul>
display to table-cell. Problem is the whole list is pushed to the right without really floating under the<div>
. https://jsfiddle.net/962m8egt/ - Add
position: relative;
andleft: 1em;
to<li>
. The problem is that this brakes accessibilty to clickable items in right floating divs. Another problem is that a long item will overlap with the right floatin box. https://jsfiddle.net/nbx8g7tv/ - Set
<ol>
list-style-position
toinside
as suggested below but it brakes the alignment of the item content when it flow on more than one line. https://jsfiddle.net/15v9s0fg/
I need a solution that work even if the content is dynamic. Whatever the width of the div (which can be replaced by an image) or the length of the list. List items have to wrap to the left around the div when the list gets longer than the div.
Here is an example with an image: https://jsfiddle.net/15v9s0fg/1/
Thanks for any better suggestion?
2
Answers
The default
list-style-position
isoutside
, you can change it toinside
for you case:https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-position
The inline style of the div element is affecting the bullet points alignment.
So for that there are 2 ways so that the right side section does not affect.
So this will add a specific height to that section and the last bullet will come in proper alignmant