Home  >  Article  >  Web Front-end  >  css 中类叠加相同属性的取值问题_html/css_WEB-ITnose

css 中类叠加相同属性的取值问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:51:271442browse

对于一个元素使用多个类,其中一个属性值在多个类中有不同取值,那么最终的该元素该属性取值是取那个呢?

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

考虑一个css链接文件盒一个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%,说明在html中一个class中并列的类书写先后顺序不影响覆盖顺序.


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

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

 

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


??

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