1

The situation is that one of the stylesheet that comes with the theme has this ol { list-style: decimal; }. However, for this specific page, I want it to use the style defined by the type property of ol element.

Eg

<ol type='a'>
  <li>first</li>
  <li>Second</li>
</ol>

or

<ol type='i'>
  <li>first</li>
  <li>Second</li>
</ol>

I tried ol { list-style: initial} and ol { list-style: inherit}, but no luck.

Can someone give me a way to reset the applied style this using CSS?

Suthan Bala
  • 3,209
  • 5
  • 34
  • 59

2 Answers2

1

When CSS property is defined in user styles globally, there is no way you can change this style from HTML attribute because of how CSS specificity is calculated.

list-style-type: initial Doesn't work either, it is used to reset to a browser, not theme default value.

So you'll have to write your own, more specific CSS. For this use case, you can use attribute selectors.

Then the result would be something like this:

HTML

 <ol type='a'>
   <li>first</li>
   <li>Second</li>
 </ol>
 <ol type='i'>
   <li>first</li>
   <li>Second</li>
 </ol>

CSS

/* Theme defined stylse */
ol {
  list-style: decimal;
}

/* Your page defined list */
ol[type='a'] {
  list-style-type: lower-alpha;
}
ol[type='i'] {
  list-style-type: lower-roman;
}

You can play with this code in codepen (codepen.io/Xopoc/pen/yPQBEM)

Xopoc
  • 254
  • 2
  • 5
0

The type attribute was deprecated in HTML4 and re-introduced in HTML5 [1]. It really shouldn't be used unless in legal documents. Ideally, you would override this in CSS. However, you can override the type attribute for a ordered list by putting a different type on each li [2]:

<ol type='i'>
  <li type="a">first</li>
  <li type="a">Second</li>
</ol>

As far as your example goes, here is a fiddle showing this technique working:

https://jsfiddle.net/jd5378mg/1/

Resources for refference:

  1. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol
  2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li
MasNotsram
  • 2,105
  • 18
  • 28