div class vs id [英] div class vs id

查看:117
本文介绍了div class vs id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用divs时最好使用类vs id?

When using divs when is it best to use a class vs id?

最好在html中使用类,字体变体或元素吗?然后对结构/容器使用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 class vs id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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