Home >Web Front-end >HTML Tutorial >About 'div#xxxx{color:blue;}_html/css_WEB-ITnose

About 'div#xxxx{color:blue;}_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:45:411725browse

I am new to the web and I don’t quite understand when I see this way of writing. Doesn’t it mean that the id is unique in a document? Then the way of writing div#xxxx means that the div element with the id of xxxx is not unique. Sorry, does the previous div seem redundant?


Reply to the discussion (solution)

The id is unique. The previous div can be omitted, but it will not go wrong if it is written. Sometimes for the sake of code For readability, it is recommended to write

div#box {
color: red;
}

==>
Elements that satisfy this selector:
1. DIV element
2. ID is "box"

Of course, if there is another selector for #box { color: blue; }
div#box { color: red; }'s weight (priority) ratio is #box { color: blue; }
, then the final content color of div is "red"

Thank you both, I understand!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn