关于“div#xxxx{color:blue;}_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:45:41
Original
1642 people have browsed it

初学web,看到这样的写法不太明白,不是说id在一个文档里面是唯一的吗,那么 div#xxxx 这样的写法意思是id为xxxx的div元素,但是id不是已经确定了唯一性了,前面的div是不是显得多余?


回复讨论(解决方案)

id是唯一的.前面的div可以不写,但写了也不会出错.有时为了代码的可读性还是建议写上

div#box {
    color: red;
}

==>
满足这个选择器的元素:
1. DIV元素
2. ID为"box"

当然,如果还有一个选择器为 #box { color: blue; }
div#box { color: red; } 的权重(优先级)比 #box { color: blue; }
则最终 div 的内容颜色为 "red"

谢谢两位,明白了!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!