0

I have a page with about 10 lists, 5 are unordered and 5 are ordered. Rather than the generic disc or bullet/number or Roman numeral I've decided to make up a custom list marker. Each list item is as so...

<ul>
  <li>*List Item 1</li>
  <li>*List Item 2</li>
</ul>

<ol>
  <li>1List Item</li>
  <li>1List Item</li>
</ol>

What I need to do is select the initial character being 1, 2 or *. Without using span 100 times or separate stylings for ul and ol, is there a way to select the first character.

I have tried using spans but with that many lists and list items there becomes a lot of extra coding...I've also tried li::first-letter {...} This works for the ul, but for ol it results in e.g. "*L" from "*List Item".

I've read a little into ":before", this would probably be the next best thing but I'm hoping there's a selector to do all li's.

Thanks for any info.

EDIT: I have found the solution using a combination of ::first-letter and ::before, like so...

<ul>
  <li>List Item</li>
  <li>List Item</li>
</ul>

<ol>
  <li>1List Item 1</li>
  <li>2List Item 2</li>
</ol>

ol li::first-letter, ul li::before {
 ... // select's all ol and all ul list items
}

ul li::before {
  content: "*";
  ... // adds * as first letter for above
}
mrkd1991
  • 388
  • 1
  • 3
  • 15
  • You have numbers in `unordered list` and what looks like custom icons in the `ordered list`. It's the wrong way around for starters. Have a look here https://stackoverflow.com/questions/10877/how-can-you-customize-the-numbers-in-an-ordered-list shows how to make custom `ol`s. > Seems I've misunderstood the question :) – Gezzasa Nov 20 '17 at 05:04
  • @Harley, as stated I've used span, but with hundreds of list items it becomes a lot of excess code to put a span on each one. – mrkd1991 Nov 20 '17 at 05:40
  • @Gezzasa, good catch! I'm writing this on my phone at work in my free time so there'll likely be a few more mistakes ha ha. Basically the first character of each list item will be wrapped in a border and styled, I want to be able to select numbers, letters and characters. – mrkd1991 Nov 20 '17 at 05:42