inherit, initial, unset, revert

发布时间:2025-08-12 05:08

There are four keywords that are valid values for any CSS property (see the title). Of those, day to day, I’d say I see the inherit used the most. Perhaps because it’s been around the longest (I think?) but also because it makes logical sense (“please inherit your value from the next parent up that sets it”). You might see that with an override of a link color, for example.

<footer> ©2012 Website — <a href="/contact">Contact</a> </footer>

/* General site styles */ a { color: blue; } footer { color: white; } footer a { color: inherit; }

That’s a decent and elegant way to handle the fact that you want the text and links in the footer to be the same color without having to set it twice.

The others behave differently though…

initial will reset the property back to the spec default.unset is weird as heck. For a property that is inherited (e.g. color) it means inherit, and for a property that isn’t inherited (e.g. float) it means initial. That’s a brain twister for me such that I’ve never used it.revert is similarly weird. Same deal for inherited properties, it means inherit. But for non-inherited properties it means to revert to the UA stylesheet. Kinnnnnda useful in that reverting display, for example, won’t make a <p> element display: inline; but it will remain a sensible display: block;.

PPK covered all this in more detail.

I’m glad he found my whining about all this:

Chris Coyier argues we need a new value which he calls default. It reverts to the browser style sheet in all cases, even for inherited properties. Thus it is a stronger version of revert. I agree. This keyword would be actually useful.

Amen. We have four properties for fiddling with the cascade on individual properties, but none that allow us to blast everything back to the UA stylesheet defaults. If we had that, we’d have a very powerful tool for starting fresh with styles on any given element. In one sense: scoped styles!

PPK has a fifth value he thinks would be useful: cascade. The idea (I suppose) is it kinda acts like currentColor except for any property. Sort of like a free variable you don’t have to define that gives you access to what the cascaded value would have been, except you’re going to use it in some other context (like a calculation).

网址:inherit, initial, unset, revert https://mxgxt.com/news/view/1671941

相关内容

Bang bang Regular Version 1.00 August 13, 2017, initial release
“追星”追的是什么
initial形象顾问具体做什么? 爱问知识人
Introduction
《太阳的后裔》女二撞脸范冰冰郑爽赵丽颖 这脸有啥问题吗
不是所有前任都是极品,这些明星的神秘前任演示了为何好聚好散
郑爽成熟大蜕变,百变造型美极了!
声入人心36名选手简单资料整理
盘点娱乐圈被指不懂知恩图报不感恩的男女明星
盘点娱乐圈十大男女明星幕后日常尴尬糗事

随便看看