CSS选择符优先级引起的样式失效_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:09:43
Original
1143 people have browsed it

选择符优先级带来的样式失效:

由于CSS选择符优先级可能引起某些样式失效,这个问题初学者可能会碰上,但是往往并不容易发现。

代码实例:

蚂蚁部落
  • 蚂蚁部落
  • div+css专区
  • HTML专区
Copy after login

以上代码可以将li元素中的所有文字设置为绿色。这个时候可能需求变了,要将第一个li元素作为标题,需要改变一下它的元素。

代码如下:

蚂蚁部落
  • 蚂蚁部落
  • div+css专区
  • HTML专区
Copy after login

尽管给第一个li元素单独设置了class类,并且规定了新的颜色,但是并没有生效。这就是由选择符优先级导致的。

只要将CSS代码做如下修改即可:

.mydiv li{color:green;} .mydiv .myli{color:blue;}
Copy after login

如需了解选择符优先级规则,可以参阅CSS选择符优先级一章节。

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1894.html

最为原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4701

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
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!