【发布时间】:2013-06-10 00:53:26
【问题描述】:
我有以下 HTML 代码,我想用 css 格式化一个无法更改的数据格式(来自 xml)。
我必须为具有不同属性值的元素赋予不同的样式。我想使用 CSS 属性选择器。
body {
background-color: black
}
s {
text-decoration: none
}
f {
color: black;
text-decoration: none;
display: block;
}
f[type=h2] {
color: green
}
f[type=p] {
color: blue
}
f[type=speech] {
color: yellow
}
f[type=other] {
color: gray
}
<b>
<s>
<f type="h2">Title</f>
<f type="p">Paragraph</f>
<f type="speech">Dialgoue</f>
<f type="other" br="true">Other</f>
<f type="p">Paragraph</f>
<f type="p">Paragraph</f>
</s>
</b>
在 Firefox 中,页面按照我的预期呈现(h2 为绿色,p 为蓝色,speech 为黄色,其他为灰色)。在 chrome 中,一切都是绿色的。
如何在 Chrome 中获取 Firefox 结果?
【问题讨论】:
-
您使用的是文档类型吗?
-
很少有人意识到您可以使用 CSS 或 XSLT 设置 XML 样式。
-
@Zenith OP 正在尝试设置 XML 文档而不是常规 HTML 的样式...
-
@MarcAudet 哎呀,这表明我可以直接进入代码!
标签: html css google-chrome css-selectors