星空网 > 软件开发 > 网页设计

CSS的优先级

样式的优先级:

(内联样式表[嵌入式样式])>(内部样式表)>(外部样式表)

经过测试动手测试发现有个(唯一的)例外 情况:当引用外部样式在内部样式表(非嵌入式样式)的后面时,外部样式会覆盖内部样式

 

测试1(插入顺序:内部样式;外部样式)

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">  <title>case</title>  <style type="text/css">    *{      margin: 0px;      padding: 0px;    }    #container{      width: 500px;      height: 500px;      background-color: black;/*黑色*/    }  </style>  <link rel="stylesheet" type="text/css" href="CaseTest1.css"><!-- 蓝色 --></head><body>  <div id="container"></div><!-- 结果:蓝色,覆盖--></body></html>

 

 

 

 

 

测试2(插入顺序:嵌入样式;外部样式)

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">  <title>case</title>  <style type="text/css">    *{      margin: 0px;      padding: 0px;    }    #container{      width: 500px;      height: 500px;    }  </style>  </head><body>  <div id="container" style="background-color: red"</div><!-- 结果:红色,没有覆盖--></body><link rel="stylesheet" type="text/css" href="CaseTest1.css"><!-- 蓝色 --></html>

 

 

 

 

测试3(外部样式;外部样式)

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">  <title>test</title>  <style type="text/css">    *{      margin: 0px;      padding: 0px;    }    #container{      width: 50px;      height: 50px;    }  </style>  <link rel="stylesheet" type="text/css" href="CaseTest.css"><!-- background-color: red;-->  <link rel="stylesheet" type="text/css" href="CaseTest1.css"><!-- background-color: blue; --></head><body>  <div id="container"></div><!-- 结果:blue--></body></html>

 

 

 

 

测试4(外部样式;嵌入样式)

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en"><head>  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">  <title>(内联样式表[嵌入式样式])>(外部样式表)</title>  <style type="text/css">    *{      margin: 0px;      padding: 0px;    }    #container{      width: 500px;      height: 500px;    }  </style>  <link rel="stylesheet" type="text/css" href="CaseTest1.css"><!-- 蓝色 --></head><body>  <div id="container" style="background-color: red"></div><!-- 结果:红色--></body></html>

 




原标题:CSS的优先级

关键词:CSS

CSS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

国际快递运费:https://www.goluckyvip.com/tag/100957.html
海瀚国际物流有限公司:https://www.goluckyvip.com/tag/100958.html
昂泰国际物流有限公司:https://www.goluckyvip.com/tag/100959.html
soundcloud:https://www.goluckyvip.com/tag/10096.html
鼎洋国际物流有限公司:https://www.goluckyvip.com/tag/100960.html
泛洋国际物流有限公司:https://www.goluckyvip.com/tag/100961.html
2024北京庞各庄镇梨花节开幕时间是几号?:https://www.vstour.cn/a/365179.html
深圳西乡三月三北帝庙会的千岁盆菜多少钱:https://www.vstour.cn/a/365180.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流