S
S
Sergey Goryachev2015-10-06 15:06:37
css
Sergey Goryachev, 2015-10-06 15:06:37

How to style li without class name?

Guys, tell me jsfiddle.net/webirus/3sgwsatq
How to specify styles for li lists correctly so as not to add class="block1" and so on.
To just write li... {background:red:} in CSS.
Is it possible to calculate the number of li in a list in CSS?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Web_Questions, 2015-10-06
@webirus

Use pseudo class nth-child
htmlbook.ru/css/nth-child
in this case
.nav li:nth-child(1) {...}
.nav li:nth-child(2) {...}
.nav li:nth-child(3) {...}
.nav li:nth-child(4) {...}
.nav li:nth-child(5) {...}
assign the .nav class to the ul tag. ..but it's optional if you don't have li anymore, you don't have to add it, but it's better to be safe

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question