前端学记之CSS-继承、优先级、层叠

来源:互联网 发布:linux sqlite 编辑:程序博客网 时间:2024/05/22 15:10

1、继承

<body style="font-family: 'Microsoft YaHei'"><div>文档头</div><div>    <p>title</p>    <span>body</span></div><div>文档尾部</div>

通过font-family属性实现继承
可继承属性:颜色、字体属性,字体颜色类

color: red;font: "";text-align: center;list-style: circle;....

不可继承属性:背景、边框、位置属性,背景边框类

background: center;border: 100px;position: absolute;....

强制继承parent的font-size属性
font-size: inherit;

2、优先级

  • 行内样式
  • id选择器
  • 类、伪类和属性选择器
  • 标签、伪元素选择器

3、层叠

  1. 属性 相同的:后面的会覆盖掉前面的
  2. 属性不相同:合并
.pic{//关键字!important会覆盖掉之前的样式     color: red !important;}
原创粉丝点击