3

span {
  float: left;
  width: 200px;
}
<ul>
  <li><span>test</span></li>
</ul>

Have a look at this in firefox vs chrome, chrome will show the bullet after the floated span element.

I'm not really sure what is happening here, seems the float is escaping the list item in webkit. Anyone come across this and know a solution?

Oriol
  • 274,082
  • 63
  • 437
  • 513
clearmend
  • 146
  • 1
  • 10

2 Answers2

4

As pointed out by @silviagreen this is a webkit-specific bug but as a workaround I suggest to add a transparent border to the list-item. This seems to properly work (but I honestly admit that I can't figure out why this should work)

li {
   border: 1px transparent solid;
}

https://jsfiddle.net/rjkz7ny1/


Other approaches suggest to change float: left into display: inline-block or to give clear: left to the list, but I feel these workarounds a bit too substantial (and not always appliable) than adding a trasparent border.

Community
  • 1
  • 1
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
  • Clever! I'd love to know why this works. Did you discover this yourself or is it a known fix for float issues? – Sabrina Feb 19 '16 at 16:55
  • @Stef I've just discovered it playing around the OP's fiddle. I've also tried a bunch of other properties with no luck – Fabrizio Calderan Feb 19 '16 at 16:56
  • @Stef: "I'd love to know why this works." Because it's WebKit ;) – BoltClock Feb 19 '16 at 16:57
  • Well kudos to you! How you even thought to try that is mind boggling. @BoltClock LOL – Sabrina Feb 19 '16 at 16:58
  • So weird. Specifically, it's `border-top`, or `padding-top`. – Oriol Feb 19 '16 at 17:05
  • But in all seriousness, I have reason to believe WebKit's implementation of `display: list-item` is way, *way* off. See http://stackoverflow.com/questions/21769248/list-with-nested-overflow-x-hidden-hides-list-counter-point-why-is-this-a-b/21778308#21778308 for an example of another WebKit list-item bug where I explain my theory. cc @Stef – BoltClock Feb 19 '16 at 17:09
0

A pseudo element, with a CSS counter for ol list can be used to avoid bug and use of borders

span {
  float: left;
  width: 200px;
}
ol {
  counter-reset:marker;
  }
li {
  counter-increment:marker;
  list-style-type:none;
  box-shadow:0 2px gray;
  }
li:before {
  content:'\02022 ';
  padding-right:0.25em;
  float:left;
  }
ol li:before {
  content:counter(marker)'. ';
  }
hr ~* li:before {
  text-indent:-1em;
  }
li:after {
  content:'';
  display:table;
  clear:both;
<ul>
  <li><span>test</span></li>
  <li><span>test</span></li>
</ul>
<ol>
  <li><span>test</span></li>
  <li><span>test</span></li>
</ol>
<hr/>
<ul>
  <li><span>test</span></li>
  <li><span>test</span></li>
</ul>
<ol>
  <li><span>test</span></li>
  <li><span>test</span></li>
</ol>
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129