样式继承

⼦元素会⾃动应⽤⽗元素的CSS样式

<div style="color: red; font-size: 20px;">
  ⽗元素
  <p>⼦元素(我没有写 color!)</p>
</div>

输出:

⾥的⽂字 也是红⾊、20px!

会继承的属性
color ⽂字颜⾊
font-family 字体
font-size 字号
font-weight 粗细
line-height ⾏⾼
text-align ⽂本对⻬
letter-spacing 字符间距
visibility 可⻅性
cursor ⿏标样式

不会继承的属性
width / height 宽⾼
margin / padding 外边距/内边距
border 边框
background 背景
display 显示类型
position 定位
float 浮动
box-shadow 盒⼦阴影

posted @ 2026-07-09 21:38  禁止睡觉stooop  阅读(5)  评论(0)    收藏  举报