Body标签上的类或ID [英] Class or ID on Body Tag

查看:237
本文介绍了Body标签上的类或ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在将HTML文档的正文标签使用ID 允许更大的CSS控制(#9)。最近,虽然发生了,我可以做完全相同的事情通过应用一个类的身体标签。我想知道每个选择的积极和消极。如果我有多个页面,其中body标签具有相同的ID,是否最好使用类?你怎么看?为什么?

I've been applying an ID to the body tag of my HTML documents lately to allow greater CSS control (#9). Recently the though occurred to me that I could do exactly the same thing by applying a class to the body tag. I want to know positives and negatives of each choice. If I have multiple pages where the body tag has the same ID, is it better to use a class? What do you think? Why?

更新:类/ ID基本上是我打算用来识别样式表哪个页面或类型的样式表被应用于样式表。

UPDATE: The class/ID is basically what I intend to use to identify to the stylesheet which page or type of page the stylesheet is being applied to. For example, is it the homepage, the contact page, one of many search results pages, an archive page, etc?

推荐答案


id选择器比类选择器更具体,它通常使它成为你的用例的更好的选择。
- David Dorward

但是,特异性并不总是令人满意。在主样式表中考虑 body#faq #col_b a {color:gray;} ,然后有人开发一个具有常规页面上的灰色背景的插件,现在他们需要使用!important 或创建另一个id属性以赋予更高的特异性。

However, a high "specificness" is not always desirable. Consider body#faq #col_b a {color:gray;} in master stylesheet and then someone develops a plugin with a gray background that goes on faq page, now they need to use !important or create another id attribute to give higher specificity.

单体元素:

<body class="faq two_column big_footer"> ...

这篇关于Body标签上的类或ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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