【CSS3】内联、内部、外部样式,样式优先级、层叠、继承

时间:2022-11-16 23:26:07
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="div.css">
<style type="text/css">
h1{color:green}
h2{color:green !important}
div{border:2px blue solid}
</style><!--属性值若为多个单词则要加引号"",否则不能加引号。!important为强制为最高优先级-->
</head>
<body>
<h1 style="color: yellow">h1标题</h1><!--离内容越近的样式优先使用!-->
<h2 style="color: yellow">h2标题</h2>
<div>
HTML5
<h3>h3标签内容继承div元素样式,但类似布局样式不能继承,例外边框</h3>
</div>
</body>
</html>
 @charset="UTF-8";
/*分号;不能省*/ h1,h2{color:red;background: blue}/*多个元素之间用逗号,多个属性之间用分号。*/
 div{color:red;background: pink}