你可以设置 noscript 元素的样式吗?
是否可以在 CSS 选择器中使用 noscript
元素?
noscript p {
font-weight: bold;
}
Is it possible to use the noscript
element in CSS selectors?
noscript p {
font-weight: bold;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的! 你绝对可以做到。
事实上,许多(
所有?)浏览器都支持使用 CSS 定位任意标签。 HTML 规范中的“官方”标签仅定义浏览器应如何使用它们。 但 CSS 是一种针对任何 XML 风格的语言,因此您可以说foo {font-weight:bold;}
并且在大多数浏览器中,hello world
将以粗体显示。正如 Darko Z 澄清的那样,IE6/7 不会添加任意内容(非标准)元素自动从源添加到 DOM; 它们必须以编程方式添加。
Yes! You can definitely do that.
In fact, many (
all?) browsers support targeting any arbitrary tag using CSS. "Official" tags in the HTML spec only define what a browser should do with them. But CSS is a language that targets any flavor of XML, so you can sayfoo {font-weight:bold;}
and in most browsers,<foo> hello world </foo>
will come out bold.As Darko Z clarifies, IE6/7 do not add arbitrary (non-standard) elements to the DOM automatically from the source; they have to be programmatically added.
我需要记住一个 IE 错误。 如果像OP一样,您只想在noscript标签内设置文本样式,而不是noscript标签本身,请忽略这一点。
假设您想将noscript标签的背景设置为红色。 在 IE8 中,它将显示启用 JS。 只是盒子本身,而不是里面的文字。
所以这个组合不好:
CSS
HTML
但这个解决方法工作正常:
CSS
HTML
奇怪的是,我只在 IE8 中看到此行为,而不是在 IE7 中。 谁知道6..
I have an IE bug to keep in mind. If, like OP, you just want to style text within the noscript tag and not the noscript tag itself, please disregard this..
Say you want to make the noscript tag's background red. In IE8, it will show up with JS enabled. Just the box itself, not the text inside.
So this combination isn't good:
CSS
HTML
But this workaround works fine:
CSS
HTML
Weirdly, I only see this behavior in IE8, not IE7. And who knows about 6..
除了 Rex M 的回答 - IE 6/7(6 def,7 也许?)不会为任意标签设置样式你。 但幸运的是,对于
所有许多 IE 问题,都有一个解决方法。假设您想要为一个名为
foo
的元素设置样式。 要让 IE 将其识别为可样式元素,您需要在 JS 中的某个位置包含此行:您不需要附加它,只需创建它。
这将使 IE 使用 CSS 规则为您设置该元素的样式:
In addition to Rex M's answer - IE 6/7 (6 def, 7 maybe?) will not style an arbitrary tag for you. But lucky for you as with
allmany IE problems there's a workaround.Say you want to style an element called
foo
. To get IE to recognise it as a styleable element you need to include this line somewhere in your JS:You don't need to append it, just create it.
This will kick IE into styling that element for you with the CSS rule: