CSS div # id for what?

in some CSS code I recognized this type of selector

div#someid
  • Is this formally correct?

  • If the answer to (1) is YES, then what does the div selector before #someid need, should not be id unique in a valid web page?

Thank!

+3
source share
6 answers

Answer: they are the same, but using a div before #id is redundant, and removing it does no harm, leaving it only in space. Some may feel that makes the markup more readable, however, since it identifies the type of element with which the identifier is associated.

, div , , #id, .

+1
  • , .
  • , , . .
+14

.

  • , . #other div.
+4

div # someid - div id someid
 #someid - id someid

0

, , CSS , , ,

#someId{
color: black;
}
.someClass{
color: green;
}

div:

<div id="someId" class="someClass">

? ( , , ID ).

, :

.someClass{
color: black;
}
div.someOtherClass{
color: green;
}

, .

, , ID , .

, , #

I) - , div # canvas > div > div # main > div: last-child > div

II) , , , .. div id "postcodeContainer", html , , ( / IDE), , div # postcodeContainer, , div.

0

, CSS, , - /.

0

Source: https://habr.com/ru/post/1736484/


All Articles