如何删除CSS元素样式内联(没有JavaScript)? [英] How can I remove CSS element style inline (without JavaScript)?

查看:597
本文介绍了如何删除CSS元素样式内联(没有JavaScript)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为样式表文件中的特定HTML元素分配了样式,例如

I have a style assigned for a specific HTML element in my stylesheet file, like this


label {
  width: 200px;
  color: red; 
}



在一个特殊情况下,我想在HTML中使用label元素文档,但忽略为标签元素指定的样式(仅适用于文档中的一个实例)。有没有办法以一个通用的方式实现这个,而不用内联样式覆盖元素样式属性?


<label for="status">Open</label>

要重申,对显示标签的HTML代码元素样式(宽度200像素,颜色红色)被申请;被应用。我想使用默认样式属性(不知道它们是什么),而不必知道在元素样式设置中具体指定什么。

To reiterate, to the HTML code displaying the label the element style (width 200 px, color red) is applied. I would like the default style attributes to be used (without knowing what they are) and without having to know what is specifically specified in the element style setting.

推荐答案

Mozilla开发人员中心


因为CSS不提供default关键字,恢复属性默认值的唯一方法是显式重新声明该属性。

Because CSS does not provide a "default" keyword, the only way to restore the default value of a property is to explicitly re-declare that property.

因此,在使用选择器(例如,通过标签名称的选择器,如p)编写样式规则时应特别小心,您可能想用更具体的规则使用id或类选择器),因为原始默认值不能自动恢复。

Thus, particular care should be taken when writing style rules using selectors (e.g., selectors by tag name, such as p) that you may want to override with more specific rules (such as those using id or class selectors), because the original default value cannot be automatically restored.

由于CSS的级联性质,以防止不打算造型的造型元件。

Because of the cascading nature of CSS, it is good practice to define style rules as specifically as possible to prevent styling elements that were not intended to be styled.

这篇关于如何删除CSS元素样式内联(没有JavaScript)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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