admin管理员组文章数量:1023628
The subject says it all. Looking for a (polyfill) code that will reset all the inherited CSS properties on a given element (such as <img>
, <a>
or <p>
).
The subject says it all. Looking for a (polyfill) code that will reset all the inherited CSS properties on a given element (such as <img>
, <a>
or <p>
).
4 Answers
Reset to default 4If you want to pletely reset everything to the browser's default styling, then the modern CSS approach is to use the revert
keyword with the all
property:
all: revert;
From MDN,
The
revert
CSS keyword rolls back the cascade so that the property takes on the value it would have had if there were no styles in the current style origin (author, user, or user-agent). In author stylesheets (the normal case), for the purposes of the given declaration, it's as if there were no author-level styles, thus resetting the property to the default value established by the user-agent stylesheet (or by user styles, if any exist).
Caveat: It is defined in the CSS Cascading and Inheritance Level 4 working draft, so browser support is currently limited to Safari only.
What you could do is create one of those elements but not attach it to the DOM. It wouldn't then receive any of the styles from your stylesheets. Then, using window.getComputedStyle
, you will get a list of the default styles.
var a = document.createElement('a');
var s = window.getComputedStyle(a);
myTargetEl.style.color = s.color; // or, use a loop to do all of them
May be you can use HTML5
boilerplate
or css Reset
to reset all the inherited CSS properties.
check these articles http://html5boilerplate./ ,
http://meyerweb./eric/thoughts/2007/05/01/reset-reloaded/
This sounds like the all
property, which sadly is not yet implemented by any browser other than Firefox.
Example:
h2 {
all: initial; // Will reset any style set for h2 elements
}
See https://developer.mozilla/en-US/docs/Web/CSS/all
The subject says it all. Looking for a (polyfill) code that will reset all the inherited CSS properties on a given element (such as <img>
, <a>
or <p>
).
The subject says it all. Looking for a (polyfill) code that will reset all the inherited CSS properties on a given element (such as <img>
, <a>
or <p>
).
4 Answers
Reset to default 4If you want to pletely reset everything to the browser's default styling, then the modern CSS approach is to use the revert
keyword with the all
property:
all: revert;
From MDN,
The
revert
CSS keyword rolls back the cascade so that the property takes on the value it would have had if there were no styles in the current style origin (author, user, or user-agent). In author stylesheets (the normal case), for the purposes of the given declaration, it's as if there were no author-level styles, thus resetting the property to the default value established by the user-agent stylesheet (or by user styles, if any exist).
Caveat: It is defined in the CSS Cascading and Inheritance Level 4 working draft, so browser support is currently limited to Safari only.
What you could do is create one of those elements but not attach it to the DOM. It wouldn't then receive any of the styles from your stylesheets. Then, using window.getComputedStyle
, you will get a list of the default styles.
var a = document.createElement('a');
var s = window.getComputedStyle(a);
myTargetEl.style.color = s.color; // or, use a loop to do all of them
May be you can use HTML5
boilerplate
or css Reset
to reset all the inherited CSS properties.
check these articles http://html5boilerplate./ ,
http://meyerweb./eric/thoughts/2007/05/01/reset-reloaded/
This sounds like the all
property, which sadly is not yet implemented by any browser other than Firefox.
Example:
h2 {
all: initial; // Will reset any style set for h2 elements
}
See https://developer.mozilla/en-US/docs/Web/CSS/all
本文标签:
版权声明:本文标题:javascript - Is there a (polyfill) code that resets all the inherited CSS properties on a given element? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745590471a2157854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论