Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make numbers in an ordered list bold?

Tags:

css

html-lists

Is there any CSS selector to attach some style to the numerical part of an ordered list only?

I have HTML like:

<ol>    <li>a</li>    <li>b</li>    <li>c</li> </ol> 

Which should output:

1.a 2.b 3.c 

I need to make 1., 2. and 3. bold, while leaving a, b, and c regular.

I am aware of the <span> workaround...

like image 465
notnull Avatar asked Jan 26 '14 22:01

notnull


People also ask

How do you make numbers bold in ordered list?

You also could put <span style="font-weight:normal"> around a,b,c and then bold the ul in the CSS.

How do I bold a number in HTML?

To bold text simply for decoration, use the CSS font-weight property instead of the HTML strong element. Let's say you want to bold a word in a paragraph — you'd wrap the word in <span> tags and use a CSS class selector to apply the font-weight property to the specific span element only.

How do you bold something in a list?

<strong> makes HTML bold text and mark it as important.


2 Answers

Counter-increment

CSS

ol {   margin: 0 0 1.5em;   padding: 0;   counter-reset: item; }  ol > li {   margin: 0;   padding: 0 0 0 2em;   text-indent: -2em;   list-style-type: none;   counter-increment: item; }  ol > li:before {   display: inline-block;   width: 1em;   padding-right: 0.5em;   font-weight: bold;   text-align: right;   content: counter(item) "."; } 

DEMO

like image 102
dcodesmith Avatar answered Oct 08 '22 05:10

dcodesmith


A new ::marker pseudo-element selector has been added to CSS Pseudo-Elements Level 4, which makes styling list item numbers in bold as simple as

ol > li::marker {   font-weight: bold; } 

It is currently supported by Firefox 68+, Chrome/Edge 86+, and Safari 11.1+.

like image 35
Kevinoid Avatar answered Oct 08 '22 04:10

Kevinoid