Div的班级vs ID [英] Div's class vs id

查看:74
本文介绍了Div的班级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屋!

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