样式优先级

  • 由上到下,由外到内。优先级由低到高。
示例代码

CSS 文件1

p
{
	text-align: center;
	color: red;	
}

CSS 文件2

p
{
	text-align: center;
	color: green;	
}

/*div 表示 p 标签往内一层*/
div p
{
	text-align: center;
	color: red;	
}

HTML 文件

<html>
	<head>
		<meta charset="UTF-8">
		<title>www.weiyuxuan.com</title>
		
		<!-- 引入两个一样的样式,使用后引入的样式 -->
		<link href="NewFile.css" type="text/css" rel="stylesheet">
		<link href="NewFile1.css" type="text/css" rel="stylesheet">
		
	</head>
	
	<body>
		<p> 你好        </p>	
		<p> 魏宇轩     </p>	
		<p> 学习 CSS </p>	
		
		<!-- 嵌套 -->
		<div><p>优先级由外到内增高</p></div>
	</body>
	
</html>

结果图:
JavaWeb_CSS(5)_样式优先级
JavaWeb_CSS(5)_样式优先级
JavaWeb_CSS(5)_样式优先级
JavaWeb_CSS(5)_样式优先级
如有错误,欢迎指正!

相关文章:

  • 2021-08-22
  • 2021-07-21
  • 2022-12-23
  • 2021-04-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
相关资源
相似解决方案