Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use list-style-type decimal but without the dots [duplicate]

Tags:

css

list

Hi,

list-style-type decimal shows lists like this:

1. apple
2. pear
3. whatever

but I dont need the dot so it looks like this:

1 apple
2 pear
3 whatever

is it possible?

Thank you.

like image 340
Cain Nuke Avatar asked May 09 '18 04:05

Cain Nuke


People also ask

How do I remove a dot from a CSS list?

Adding the "list-style: none" CSS class to the unordered list (<ul>) or ordered list (<ol>) tag removes any bullet or number.

What does list-style type none do?

The list-style-type property in CSS specifies the appearance of the list item marker (such as a disc, character, or custom counter style) if 'list-style-image' has the value 'none'.

What is unordered list item marker?

In HTML, there are two main types of lists: unordered lists (<ul>) - the list items are marked with bullets. ordered lists (<ol>) - the list items are marked with numbers or letters.

What is the default list-style for an ordered list UL?

The default list-style-type value for an ordered list is decimal , whereas the default for an unordered list is disc .


1 Answers

Use CSS Counters or CSS Markers. Ordered lists have a default counter named list-item you don't have to reset or increment, so the following is equivalent when using the default 0+1 ordering (starting at 0 and incrementing by 1)

Thanks goes out to fcrozatier for pointing out the default behavior of list-item of an <ol>.

html {
  font: 300 2ch/1.2 'Segoe UI'
}

/* ::before Solution */
.A {
  list-style: none;
  margin-left: -1rem;
}

/* The "\a0" is a space */
.A li::before {
  content: counter(list-item)"\a0\a0";
}

/* ::marker Solution */
.B li {
  list-style: none;
  padding: 0;
}

.B li::marker {
  content: counter(list-item)"\a0\a0";
}
<ol>
  <li>Default style of &lt;ol&gt;</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
</ol>

<ol class='A'>
  <li>Custom style using <code>::before</code> pseudo-element</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
</ol>

<ol class='B'>
  <li>Custom style using <code>::marker</code> pseudo-element</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
</ol>
like image 151
zer00ne Avatar answered Sep 21 '22 10:09

zer00ne