当前位置:网站首页>initial、inherit、unset、revert和all的区别
initial、inherit、unset、revert和all的区别
2022-07-03 11:56:00 【师兄白泽】
initial
表示元素属性的初始默认值(该默认值由官方CSS规范定义)
示例
<p>
<span>This text is red.</span>
<em>This text is in the initial color (typically black).</em>
<span>This is red again.</span>
</p>
p {
color: red;
}
em {
color: initial;
}

inherit
表示元素的直接父元素对应属性的计算值,inherit 关键字只是增强了属性的默认行为,通常只在覆盖原有的值的时候使用。继承始终来自文档树中的父元素,即使父元素不是包含块。
/* 设置二级标题的颜色为绿色 */
h2 {
color: green; }
/* ...but leave those in the sidebar alone so they use their parent's color */
#sidebar h2 {
color: inherit; }
unset
unset相对于initial和inherit而言,相对复杂一点。表示如果该属性默认可继承,则值为inherit;否则值为initial。实际上,设置unset相当于不设置
<p>This text is red.</p>
<div class="foo">
<p>This text is also red.</p>
</div>
<div class="bar">
<p>This text is green (default inherited value).</p>
</div>
.foo {
color: blue;
}
.bar {
color: green;
}
p {
color: red;
}
.bar p {
color: unset;
}

revert
表示样式表中定义的元素属性的默认值。若用户定义样式表中显式设置,则按此设置;否则,按照浏览器定义样式表中的样式设置;否则,等价于unset
<h3 style="font-weight: revert; color: revert;">
This should have its original font-weight (bold) and color: black
</h3>
<p>Just some text</p>
<h3 style="font-weight: unset; color: unset;">
This will still have font-weight: normal, but color: black
</h3>
<p>Just some text</p>
h3 {
font-weight: normal;
color: blue;
}

all
表示重设除unicode-bidi和direction之外的所有CSS属性的属性值,取值只能是initial、inherit、unset和revert
<style> .test{
border: 1px solid black; padding: 20px; color: red; } .in{
/* all: initial; all: inherit; all: unset; all: revert; */ } </style>
<div class="test">
<div class="in">测试文字</div>
</div>
边栏推荐
- Tensorflow binary installation & Failure
- Sword finger offer09 Implementing queues with two stacks
- 02_ Lock the code, and don't let the "lock" become a worry
- Apprendre à concevoir des entités logicielles réutilisables à partir de la classe, de l'API et du cadre
- regular expression
- 写一个简单的nodejs脚本
- Integer string int mutual conversion
- ES6新特性
- Is it safe to open an account for online stock speculation? Who can answer
- 实现验证码验证
猜你喜欢

(最新版) Wifi分销多开版+安装框架
![Sword finger offer04 Search in two-dimensional array [medium]](/img/c4/002c951f8d914aaea4f4133685ebd1.png)
Sword finger offer04 Search in two-dimensional array [medium]

idea将web项目打包成war包并部署到服务器上运行

Shutter: add gradient stroke to font

Integer string int mutual conversion

Shutter: overview of shutter architecture (excerpt)

剑指Offer05. 替换空格

Sword finger offer06 Print linked list from end to end

社交社区论坛APP超高颜值UI界面

Sword finger offer07 Rebuild binary tree
随机推荐
Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
Sword finger offer05 Replace spaces
2020-10_ Development experience set
Apprendre à concevoir des entités logicielles réutilisables à partir de la classe, de l'API et du cadre
Idea packages the web project into a war package and deploys it to the server to run
Wechat applet pages always report errors when sending values to the background. It turned out to be this pit!
雲計算未來 — 雲原生
Use of atomicinteger
MySQL time zone solution
剑指Offer03. 数组中重复的数字【简单】
adb push apk
lambda与匿名内部类的区别
If you can't learn, you have to learn. Jetpack compose writes an im app (II)
双链笔记·思源笔记综合评测:优点、缺点、评价
Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)
ImportError: No module named examples. tutorials. mnist
1-2 project technology selection and structure
232. Implement queue with stack
LeetCode 0556. Next bigger element III - end of step 4
网上炒股开户安不安全?谁给回答一下