CSS Inheritance
2015-06-09 13:50
447 查看
HTML elements can inherit CSS styles from their parent elements. This is called CSS inheritance. Here is a CSS inheritance example:
<div> <p> This text inherits the font-size of the parent div element. </p> </div> <style> div { font-family: Aial; } </style>
In this example the
divelement has the
font-familyproperty set to
Arial. This CSS property is inherited by the nested
pelement, so it will also have its CSS property
font-familyset to
Arial.
HTML elements can inherit styles from more remote ancestors too, and not just from their parents. Look at this example:
<body> <div> <p> This text inherits the font-size of the parent div element. </p> </div> <style> body { font-family: Aial; } </style> </body>
In this example the CSS property
font-familyis set on the
bodyelement. This CSS property is then inherited by the
divand
pelements.
Not all styles are inherited from a parent or ancestor element. Generally, styles that apply to text are inherited, whereas borders, margins and paddings and similar styles are not.
相关文章推荐
- css3中浏览器厂商前缀
- css-文本垂直居中(转)
- 页面文案展开和收缩样式的操作
- CSS3的文字阴影—text-shadow
- Html+Css新手简单快速仿京东商品分类导航
- Css 外边距折叠(collapsed margin ) 浅析
- 修改列表的行样式
- CSS---清除浮动
- css基础知识
- css 背景色渐变---和背景色透明
- css骇客编码,兼容例子
- 常用的CSS代码
- 下拉列表框Spinner-采用自定义布局文件作为Spinner样式
- css3 在线编辑工具 连兼容都写好了
- css3之outline属性
- HTML第二十节(CSS制作照片墙效果与瀑布流)
- HTML+CSS样式设置——CSS一学就会
- 让navigationItem.leftBarButtonItem具有backBarButtonItem的外观样式
- HTML和CSS书写心得
- CSS--使用伪选择器制作箭头图标