html – Chrome和CSS属性选择器

前端之家收集整理的这篇文章主要介绍了html – Chrome和CSS属性选择器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有以下HTML代码,我想用css格式化一种无法更改的数据格式(来自xml).

我必须为具有不同属性值的元素提供不同的样式.我想使用CSS属性选择器.

  1. body {
  2. background-color: black
  3. }
  4. s {
  5. text-decoration: none
  6. }
  7. f {
  8. color: black;
  9. text-decoration: none;
  10. display: block;
  11. }
  12. f[type=h2] {
  13. color: green
  14. }
  15. f[type=p] {
  16. color: blue
  17. }
  18. f[type=speech] {
  19. color: yellow
  20. }
  21. f[type=other] {
  22. color: gray
  23. }

在Firefox中,页面按照我的预期呈现(h2为绿色,p为蓝色,语音为yelllow,其他为灰色).在chrome中,一切都是绿色的.

如何在Chrome中获取Firefox结果?

最佳答案
由于某些未知原因,Chrome对HTML标记非常严格,因此CSS规则在上述浏览器中无法正常工作.

不过有个建议,你为什么不style the XML呢?

猜你在找的HTML相关文章