全部覆盖CSS属性:未设置 [英] Overriding CSS property all: unset

查看:154
本文介绍了全部覆盖CSS属性:未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在开发的CSS框架,我正在使用all: unset,它本身可以正常工作:

For a CSS framework I am developing, I am using all: unset, which by itself works fine:

#foo { all: unset; }

但是,在某些情况下,我想撤消"此规则的效果,如

However, in certain cases, I want to "undo" the effect of this rule, as in

#foo:hover { all: auto; }

但是,这显然不起作用,因为all没有auto的值.取而代之的是,我们有值inheritinitial,而不是取消" all属性,它们具有不同的效果:将所有值恢复为其父级的值或它们的初始值(我假设这意味着系统级默认值).

However, this obviously does not work because there is no value of auto for all. Instead, we have the values inherit and initial, which instead of "cancelling" the all property, have different effects: of reverting all values to their parent's value, or their initial (I assume this means system-level default values).

要完成我想要的事情,我目前正在做

To accomplish what I want, I am currently doing

#foo:not(:hover) { all: unset; }

可以正常工作,但是如果我想对多个伪类执行此操作,则伸缩性不太好,并且我想覆盖all: unset属性?有什么办法吗?

which works fine, but is not too scalable if I want to do this for multiple pseudo-classes, for example, and I would prefer to override the all: unset property? Is there any way to do so?

推荐答案

一旦指定了all属性,似乎无法撤消其效果.这可能是由于all是一种简写属性(恰好只接受CSS范围内的关键字作为值).

It does not appear to be possible to undo the effects of the all property once it has been specified. This may be due to all being a shorthand property (that happens to accept only the CSS-wide keywords as values).

您不能像使用css-cascade-4引入revert关键字一样删除级联中的速记声明,这是因为速记属性不存在,因为自己在级联中的实体;相反,它仅表示其所有组件属性.像更传统的速记属性(例如backgroundfont)一样,覆盖已应用的速记声明的唯一方法是通过速记声明或通过其他方法重新指定被覆盖的速记值.速记声明.但是您不能使用all属性来实现后者,因为它仅接受CSS范围的关键字.

You can't erase a shorthand declaration from the cascade the same way that css-cascade-4's introduction of the revert keyword allows you to erase author-level declarations, and that's because a shorthand property doesn't exist as its own entity in the cascade; instead, it simply represents all of its component properties. Like with the more traditional shorthand properties such as background and font, the only way to override a shorthand declaration that has been applied is to re-specify the values for the longhands that were overridden, either via longhand declarations or via another shorthand declaration. But you can't do the latter with the all property since it only accepts CSS-wide keywords.

由于前者显然不适用于all速记,因为您无法预测开始要覆盖哪些作者级别的声明,因此,您唯一的选择是通过选择器对其进行限制,从而阻止它从一开始就在特定情况下应用.希望在不久的将来我们将看到更多4级:not()的实现,这将使编写选择器更加容易.

As the former is obviously not practical with the all shorthand, since you can't predict which author-level declarations are being overridden to begin with, your only other option is to restrict it via a selector, thereby preventing it from ever applying in specific circumstances in the first place. Hopefully we will see more implementations of level 4 :not() in the near future, which will make writing selectors a little easier.

这篇关于全部覆盖CSS属性:未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆