级联样式表使用“id”或“类” [英] Cascading style sheets use "id" or "class"

查看:129
本文介绍了级联样式表使用“id”或“类”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当样式化特定的html元素时,我倾向于总是使用类属性。



为什么两个都存在,你应该使用什么和什么时候?解决方案

id id 定义元素。 class class ify元素。



(例如地址)



如果 ...

when styling specific html elements, i tend to always use the class attribute. the css code looks cleaner imo.

why do both exist which one should you use and when ?

解决方案

ids identify elements. classes classify elements.

Put a class on an element if "it's a kind of ..." (e.g. address)

Put an ID on an element if "it is the ..." (e.g. navigation)

这篇关于级联样式表使用“id”或“类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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