Div的班级vs ID [英] Div's class vs id
问题描述
使用divs
时,什么时候最好使用class
vs id
?
When using divs
when is it best to use a class
vs id
?
在字体变体或html中的元素上最好使用class
吗?然后对结构/容器使用id
吗?
Is it best to use class
, on say font variant or elements within the html? Then use id
for the structure/containers?
这是我一直不确定的事情,任何帮助都会很棒.
This is something I've always been a little uncertain on, any help would be great.
推荐答案
使用id
来标识页面上将只有一个实例的元素.例如,如果您将单个导航栏放置在特定位置,请使用id="navigation"
.
Use id
to identify elements that there will only be a single instance of on a page. For instance, if you have a single navigation bar that you are placing in a specific location, use id="navigation"
.
使用class
对所有以某种方式表现的元素进行分组.例如,如果您希望公司名称在正文中以粗体显示,则可以使用<span class='company'>
.
Use class
to group elements that all behave a certain way. For instance, if you want your company name to appear in bold in body text, you might use <span class='company'>
.
这篇关于Div的班级vs ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!