前端学习

css中的属性继承

2017-08-04  本文已影响67人  FFriday

在css中我们在父级元素上设置了css样式后,子级元素也会受到同样的影响,那么这些属性就是可以被继承的,反之就是不可以被继承。

首先我们先看一下不可以继承的css属性

<!--  不可继承的属性
display、margin、border、padding、background、
height、min-height、max- height、
width、min-width、max-width、overflow、
position、left、right、top、 bottom、
z-index、float、clear、table-layout、
vertical-align、page-break-after、 page-bread-before、unicode-bidi
-->


<div style="border:1px solid #ff0000;margin:10px">
    这是父节点,会受到设置样式的影响。
    <p>
         这是子节点,border、margin是不可继承的属性,所以不会受到影响
    </p>
</div>

有些是指定类型的元素可以继承的属性

// 表格元素可继承:border-collapse。
<style type="text/css">
  table { border-collapse:collapse;}
  table, td, th {  border:1px solid black;}
</style>
<table>
  <tr>  <th>Firstname</th> <th>Lastname</th> </tr>
  <tr> <td>Bill</td> <td>Gates</td> </tr>
  <tr>  <td>Steven</td> <td>Jobs</td>  </tr>
</table>

// 块级元素可继承:text-indent和text-align

// 列表元素可继承:list-style、list-style-type、list-style-position、list-style-image。

// 行内(内联)元素可继承:letter-spacing、word-spacing、white-space、line-height、color、font、font-family、
font-size、font-style、font-variant、font-weight、text- decoration、text-transform、direction。

所有元素均可继承

// visibility: 元素是否可见
// cursor: 属性规定要显示的光标的类型(形状)
上一篇 下一篇

猜你喜欢

热点阅读