The above solutions all have drawbacks for some lists: multiline items, multidigit item numbers, custom background, etc.
It's cleaner to use the built-in list-item
counter instead of a custom counter:
ol.dotless {
list-style-type: none;
margin-left: 0;
}
ol.dotless > li:before {
content: counter(list-item) "\A0";
float: left;
text-align: right;
width: 1.5em;
}
But this approach does not work with multiline items.
There is a new method that allows you to directly format a counter, but so far, it only works in Firefox:
ol.dotless {
list-style: dotless-item
}
@counter-style dotless-item {
system: numeric;
symbols: "0" "1" "2" "3" "4" "5" "6" "7" "8" "9";
suffix: " ";
}
The only method I've come across that works in all cases is a table
that mimics an ol
:
table.dotlessol {
margin: 0.25em 1.25em;
border-spacing: 0;
counter-reset: dotless;
}
table.dotlessol tr {
vertical-align: top;
counter-increment: dotless;
}
table.dotlessol td {
padding: 0;
}
table.dotlessol td:first-child {
text-align: right;
padding-right: 0.5em;
}
table.dotlessol td:first-child::before {
content: counter(dotless);
}
Use two td
s in each row, leave the first td
empty, and put the item text in the second td
.
<ul>
– Saltation