Стили для нумерованных списков ol

Несколько примеров как задать стили у нумерации списков с применением счетчика counter и псевдоэлемтов :before и :after.

HTML разметка

<ol>
	<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
	<li>Nulla facilisi etiam dignissim diam quis enim</li>
	<li>Sit amet purus gravida quis blandit turpis</li>
	<li>Mauris cursus mattis molestie a iaculis at erat pellentesque adipiscing</li>
</ol>
HTML
1
ol {
	list-style-type: none; 
	counter-reset: num;
	margin: 0 0 0 35px;
	padding: 15px 0 5px 0;
	font-size: 18px;
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
}
ol li:before {
	content: counter(num) '.'; 
	counter-increment: num;
	display: inline-block;	
	position: absolute;
	top: 0px;
	left: -26px;
	width: 20px;    
	color: #ef6780;
	text-align: right;
}
CSS
2
ol {
	list-style-type: none; 
	counter-reset: num;
	margin: 0 0 0 60px;
	padding: 15px 0 5px 0;
	font-size: 16px;
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
}
ol li:before {
	content: counter(num); 
	counter-increment: num;
	display: inline-block;
	position: absolute;
	top: 0px;
	left: -60px;
	width: 50px;    
	color: #ef6780;
	text-align: center;
	font-size: 40px;
	font-weight: bold;
}
CSS
3
ol {
	list-style-type: none; 
	counter-reset: num;
	margin: 0 0 0 45px;
	padding: 15px 0 5px 0;
	font-size: 16px;
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
	line-height: 1.4;
}
ol li:before {
	content: counter(num); 
	counter-increment: num;
	display: inline-block;
	position: absolute;
	top: 0;
	left: -38px;
	width: 28px;
	height: 28px;
	background: #ef6780;
	color: #fff;
	text-align: center;
	line-height: 28px;
	font-size: 18px;
}
CSS
4
ol {
	list-style-type: none; 
	counter-reset: num;
	margin: 0 0 0 45px;
	padding: 15px 0 5px 0;
	font-size: 16px;
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
	line-height: 1.4;
}
ol li:before {
	content: counter(num); 
	counter-increment: num;
	display: inline-block;
	position: absolute;
	top: 0;
	left: -38px;
	width: 28px;
	height: 28px;
	background: #fff;
	color: #000;
	text-align: center;
	line-height: 28px;
	font-size: 18px;
	border-radius: 50%;
	border: 1px solid #ef6780;
}
CSS
5
ol {
	list-style-type: none; 
	counter-reset: num;
	margin: 0 0 0 60px;
	padding: 15px 0 5px 0;
	font-size: 16px;
	position: relative;	
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
	line-height: 1.4;
}
ol li:before {
	content: counter(num); 
	counter-increment: num;
	display: inline-block;
	position: absolute;
	top: 0;
	left: -55px;
	width: 28px;
	height: 28px;
	background: #fff;
	color: #000;
	text-align: center;
	line-height: 28px;
	font-size: 18px;
	border-radius: 50%;
	border: 1px solid #ef6780;
}
/* Вертикальная линия */
ol:before {
	content: ''; 
	position: absolute;
	top: 15px;
	bottom: 15px;
	left: -15px;
	width: 1px;
	border-left: 1px solid #ef6780;
}
CSS
6
ol {
	list-style-type: none; 
	counter-reset: num;
	position: relative;	    
	margin: 0 0 0 60px;
	padding: 15px 0 5px 0;
	font-size: 16px;
}
ol li {
	position: relative;	
	margin: 0 0 0 0;
	padding: 0 0 10px 0;
	line-height: 1.4;
}
ol li:after {
	content: counter(num); 
	counter-increment: num;
	display: inline-block;
	position: absolute;
	top: 0;
	left: -45px;
	width: 28px;
	height: 28px;
	line-height: 28px;
	background: #fff;
	color: #000;
	text-align: center;
	font-size: 18px;
	border-radius: 50%;
	border: 1px solid #ef6780;
}

/* Вертикальная линия */
ol:before {
	content: ''; 
	position: absolute;
	top: 15px;
	bottom: 15px;
	left: -30px;    
	width: 1px;
	border-left: 1px solid #ef6780;
}
/* Скрытие линии у последнего li */
ol li:last-child:before {
	content: ''; 
	display: inline-block;
	position: absolute;
	top: 0;
	bottom: 0;
	left: -38px;
	width: 28px;
	background: #fff;
}
CSS
24.03.2019, обновлено 24.10.2019
43539

Комментарии

, чтобы добавить комментарий.

Другие публикации

Модальные окна на Fancybox 2
Fancybox 2 не только плагин галерей, но и модальных окон, рассмотрим подробнее.
23403
+4
Стилизация Checkbox
Несколько примеров как изменить внешний вид чекбоксов с помощью CSS, изображений и немного JS.
74115
+3
Contenteditable – текстовый редактор
Если добавить атрибут contenteditable к элементу, его содержимое становится доступно для редактирования пользователю, а...
43715
+34
Как преобразовать текст из textarea в параграфы HTML
Такой вопрос возникает при вставке текста из формы на сайт (отзывы, комментарии и т.д.) с форматированием элементом p.
7180
+3
Меню-подсказка на затемненном фоне
Пример реализации всплывающей подсказки или меню с затемнением фона на jQuery и CSS, в верстке использованы блок со...
5710
-1
Модальные окна на Fancybox 3
Fancybox 3 плагин галерей и модельных окон, в отличии от второй версии существенно изменилась скорость работы, дизайн и немного API, далее подробнее о вызове модальных окон.
65120
+2