11

I'm inclined to think this is a bug in Chrome (why would a style on a child element affect the parent?), but there might be something else going on that I'm not understanding.

The ordered list below has 1 item, which in Firefox and IE10 is numbered (although in IE, it's positioned wrong). In Chrome though, the number is hidden entirely.

ol {
  list-style-position: outside;
}
div {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  width: 150px;
}
<ol>
  <li>
    <div>Some text that trails off</div>
  </li>
</ol>

What's going on/is this a bug/can this be worked around?

Izkata
  • 8,961
  • 2
  • 40
  • 50
  • Do you require overflow:hidden on the div? Is this necessary. If you remove it you can see the number in chrome. – lharby May 12 '15 at 15:10
  • @lharby This was simplified from code that has 2 divs in the li, and involves `text-overflow: ellipses` – Izkata May 12 '15 at 15:11
  • @LuisP.A. "upper" doesn't exist – Izkata May 12 '15 at 15:12
  • @Izkata..yes you are right, my mistake . Is decimal – Luís P. A. May 12 '15 at 15:15
  • @LuisP.A. All that does is set it to use numbers, which is the same as the default for `
      `
    – Izkata May 12 '15 at 15:16
  • It depends how you want to attack it then, would a js solution be OK? I use this http://rafael.adm.br/css_browser_selector/ it adds a class to the html which allows you to write vendor specific css. so .firefox ol { //your code here }, modernizr also uses this technique, but that might be very heavy. Otherwise I suppose you might need a conditional stylesheet. Was looking here but it's quite dirty: https://css-tricks.com/snippets/css/browser-specific-hacks/ – lharby May 12 '15 at 15:18
  • @Izkata..sometimes we need to force the style...this is why -http://stackoverflow.com/questions/11737266/what-is-default-list-styling-css . just a precaution. – Luís P. A. May 12 '15 at 15:21
  • @LuisP.A. Luckily our reset.css does not include that – Izkata May 12 '15 at 15:23

4 Answers4

3

Well, this is a kind of a hack, but it works. Adding a pseudo :before-element brings back the list style, as the li will have some content now. Bring back the div to the top and it looks like nothing has changed.

CSS

ol > li:before {
    content: '';
    display: block;
    height: 1px;
}

div {
    margin-top: -1px;
}

Demo

Try before buy

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
  • ..this has me going WTF even more, but it works completely. Firefox and Chrome both look the same now. – Izkata May 12 '15 at 15:32
  • So I undid this and added some text in the
  • but outside the "overflow:hidden" div, and the number for that
  • reappeared. Does Chrome/Webkit have some secret psuedo-property akin to IE's `hasLayout`, that "overflow:hidden" undoes?
  • – Izkata May 12 '15 at 15:37
  • 1
    Basically my solution does excactly what you have done manually by inserting some content. It seems that Webkit has a problem, when only block-level elements (even `inline-block` is working) with `overflow:hidden;` appear. My answer is a workaround to add some invisible content, without destroying the layout. – insertusernamehere May 12 '15 at 15:42
  • In my case, I solved this problem by adding `list-style-position: inside` on list block – pkirilin Jan 12 '22 at 08:53