前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >INHERITED AND NON-INHERITED IN CSS

INHERITED AND NON-INHERITED IN CSS

作者头像
牧云云
发布2019-12-31 12:04:24
3050
发布2019-12-31 12:04:24
举报
文章被收录于专栏:云瓣云瓣

When I look up css properties in MDN's specifications section, there are some properties in it and it seems unfamiliar to me. So I try to find out some of them today.

Initial value between inherited and non-inherited

The initial value of a CSS property is its default value.

The Initial value has two different behavior between inherited properties and non-inherited properties.

For inherited properties, the initial value is used on the root element only.

代码语言:javascript
复制
<span style="color: red">
  hello, <em>CSS</em>
</span>

The result is the color of both span and em element are red. Because the color is an inherited property, the element will get the color property from the parent recursively until to document.

For non-inherited properties, the initial value is used on every element. When no value for a non-inherited property has been specified on an element, the element gets the initial value directly.

代码语言:javascript
复制
<span style="border: 1px solid black">
  hello, <em>CSS</em>
</span>

The result is the border is only effected on span element, not em. Because the border is a non-inherited property, and there is no border property specified on the em, so the em get the border's initial value none.

It mentioned much times about inherited value and non-inherited value above, and now we sort out css properties.

Inherited Type

I've collected some inherited types in css, they are listed as follow:

  • Font Type: font-style、font-variant、font-weight、font-stretch、font-size、font-family、color、line-height;
  • Space Type: letter-spacing、word-spacing、white-space;
  • Letter Type: text-align、text-indent、text-shadow、text-transform;
  • List Type: list-style、list-style-type、list-style-position;
  • Others: visibility、cursor;

Non-Inherited Type

In the opposite of inherited type, the non-inherited types are listed as follow:

  • Layout Type: float、position、left、right、top、bottom、z-index、display
  • Box Type: width、max-width、min-width、height、max-height、min-height、margin、padding、border;
  • Background Type: background-size、background-image、background-clip、background-color、background-origin、background-position、background-repeat;
  • Others: overflow、text-overflow、vertical-align;

Recap

These section introduces the inherited concept in CSS, and distinguish some inherited type and some non-inherited type from css properties. Hope it's helpful for you.

Read More

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-12-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Initial value between inherited and non-inherited
  • Inherited Type
  • Non-Inherited Type
  • Recap
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档