程序员人生 网站导航

css 中类叠加相同属性的取值问题

栏目:htmlcss时间:2015-01-05 08:14:14

对1个元素使用多个类,其中1个属性值在多个类中有不同取值,那末终究的该元素该属性取值是取那个呢?

固然是优先级高的覆盖优先级低的。

斟酌1个css链接文件盒1个html文件。

css中:

.form-control{ width: 100% ; ... } .width-control{ width:60% ; }


html中:

1. <div class="form-control width-control">...</div> 2. <div class="width-control form-control">...</div>


上述在html中改变类的书写顺序,发现有效值均为width:60%,说明在html1个class并列的类书写前后顺序不影响覆盖顺序.


改变在css中定义的顺序,以下:

.width-control{ width:60% ; } .form-control{ width: 100% ; ... }

 

此时有效值均为width:100%, 这说明类的优先级是由类在css文件中定义的顺序决定的:越后定义优先级越高!



------分隔线----------------------------
------分隔线----------------------------

最新技术推荐