为什么使用id&类的html为什么不只是一个? [英] why use id's & class's in html why not just one?
问题描述
我知道id和类的id之间有一个区别,给予一个唯一的项目,类的和类似的标签,他们可以给予多个项目。
i understand what there is a difference between id's and class's - ids and ment to be given to a unique item, and class's and like tags, they can be given to multiple items..
但是为什么你需要有两个,在过去,我曾经使用#id写的一切(这是当我是写html和did not知道任何不同),代码仍然工作..
but why do you need to have both, in the past i used to write everything using #id (this was when i was new to writing html and didnt know any different) and the code still worked.. would not have been 100% valid but still worked.
我知道现在使用html5你可以定义区域不同,但是这不是说使用html5
i know now using html5 you can define areas differently, but for this im not talking about using html5
推荐答案
想象一下,如果你有一个按钮在页面上看起来是一样的。 您希望在CSS中重复多次吗?
Imagine if you had a load of buttons that looked the same on the page. Would you want to repeat yourself numerous times in your CSS? Or use a class and write it once.
这适用于不同元素上相同样式的任何情况。
This is applicable in any case of the same styling on different elements.
这篇关于为什么使用id&类的html为什么不只是一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!