I am creating a rules page for a game, and the design specs have the rules in an ordered list without the period after each number:
1 Rule one
2 Rule two
3 Rule three
I removed the dot using this code:
ol {
list-style-type: none;
margin-left: 0px;
}
ol > li {
counter-increment: customlistcounter;
}
ol > li:before {
content: counter(customlistcounter) " ";
font-weight: bold;
float: left;
width: 3em;
}
ol:first-child {
counter-reset: customlistcounter;
}
But now when the rules text reaches the second line, the text starts directly underneath the number instead of underneath the beginning of the first line of text.
1 this is what I want
to happen
2 this is what is actually
happening
Just in case it’s helpful, here’s the relevant html:
<ol>
<h2 class="uppercase title fs-500 text-mid">How to Play</h2>
<li class="fs-400">
Red goes first in the first game.
</li>
<li class="fs-400">
Players must alternate turns, and only one disc can be dropped in each turn.
</li>
<li class="fs-400">
The game ends when there is a 4-in-a-row or a stalemate.
</li>
<li class="fs-400">
The starter of the previous game goes second on the next game.
</li>
</ol>
I tried to adjust it with margins and padding, but either it ended up overflowing or doing nothing.
2
Answers
Try this:
CSS:
Note:
:before
has two colons:::before
The
@counter-style
at-rule lets you define counter styles that are not part of the predefined set of styles.You can style the number with the
::marker
pseudo-element.BTW, it is invalid to have
h2
as a child ofol
. You’ll need to apply margin and/or padding for the desired styling to match the padding ofol
.