4

Consider the following code:

<ol class=top>
  <li>Top item

    <ol>
      <li>Sub</li>
      <li>list</li>
      <li>item.</li>
    </ol>
  </li>
</ol>

And css:

.top > li {
  text-decoration: underline;
}

.top ol li {
  text-decoration: none;
}

Fiddle: http://jsfiddle.net/fLvns1z0/1/

I want only the "Top item" be underlined, but instead whole text is underlined. Even !important doesn't help. Any ideas how to make it work and keep the code as simple as possible?

Stalinko
  • 3,319
  • 28
  • 31
  • I take back my previous comment. It does make sense when use a different example: http://jsfiddle.net/3rror404/ntLgkmap/1/ – Turnip Jul 16 '18 at 10:53
  • @Turnip for the last one it's logical, as the span is inline and will get the style of underline (this is a known behavior) make it inline-block and it will change – Temani Afif Jul 16 '18 at 10:53
  • Yes, you are correct. @TemaniAfif – Turnip Jul 16 '18 at 10:55
  • @Turnip check the second example of my answer, inline-block will cancel the effect – Temani Afif Jul 16 '18 at 10:59