CSS doesn't care,But Javascript cares.
引用
ID's are unique.
Each element can only have only one ID.
Each page can have only one element with that ID
Classes are NOT unique
You can use the same class on multiple elements.
You can use multiple classes on the same element.
id是唯一的,class是可以复用的。
web标准中不允许出现两个div的id标识是相同的,id也是js获取对象的一个标示,所以也必须是唯一的。
class还有一个有点,就是一个div中可以使用多个class.
class跟id的比较:
如果没有特殊的要求,可以
尽量的使用class,因为使用class更加的灵活。但是需要用到javascript的时候,便要使用id。
class更多的被应用到文字版块以及页面修饰等方面,而id更多地被用来实现宏观布局和手机包含块,或包含框的样式。
即id用于布局,class用于样式。
id样式优先级高于class样式
参考资料:
http://css-tricks.com/the-difference-between-id-and-class/
http://ryanfait.com/articles/the-difference-between-ids-and-classes/
http://stackoverflow.com/questions/544010/css-div-id-vs-div-class
分享到:
相关推荐
Python是机器学习中最常用的语言,因为它拥有丰富的库和工具,如NumPy、Pandas、Matplotlib以及Scikit-Learn等,它们为数据预处理、模型构建、训练和评估提供了便利。在处理数据集时,我们首先会用到Pandas库,它...
很抱歉,根据您提供的信息,"【天池】2020数字中国创新大赛数字政府赛道智慧海洋建设——复赛0.904融合模型.zip"是一个比赛相关的压缩包文件,但具体的文件列表中只有一个看似不完整的条目"222二婷3789",这并不足以...
《邢不行——量化投资新手学习大礼包》是一个针对量化投资初学者精心编纂的资源集合。这个压缩包可能包含了各种教程、案例分析、代码示例、研究报告等,旨在帮助新手快速掌握量化投资的基础知识和实战技能。下面,...
Each CSS chapter comes with an end-of-chapter exercise where you get to practice the different CSS properties covered in the chapter and see first hand how different CSS values affect the design of ...
Learn the real secrets of creating Web pages, and why everything your boss told you about HTML tables is probably wrong (and what to do instead). Most importantly, hold your own with your co-worker ...
Finally you'll learn how to use Swift alongside Objective-C as well as with Core Data, and you'll learn how to put all of the pieces together with a health app using Apple's new HealthKit framework. ...
The Way to Go,: A Thorough Introduction to the Go Programming Language 英文书籍,已Cross the wall,从Google获得书中源代码,分享一下。喜欢请购买正版。 目录如下: Contents Preface......................
As we learn more about the human brain, for example, we face new challenges in understanding the nature of consciousness and the relationship between mind and body. In the arts and humanities, the ...
This crash course about CSS is not only going to teach you the basics of CSS in a didactic way, furthermore, you will learn CSS WHEN you want, and more important, WHERE you want (It could even be at ...
Short chapters are paired with free interactive online exercises to teach the fundamentals of HTML and CSS. Written for beginners, useful for experienced developers who want to sharpen their skills. ...
With the advent of Microsoft® DirectX® version 8.0, the revolution of programmable ... Read on, be illuminated, and learn how to create your own effects using the programmable graphics pipeline.
Students learn about class syntax, access specifiers, data and function members, constructors and destructors, composition, static members, and the use of constants in object-oriented design....
Manage complex projects with a programmer’s text editor Leverage the immense power of data structures Apply algorithms to process your data structures Master indispensable text parsing and processing...
Shaw is the author of the popular online books Learn Python the Hard Way, Learn Ruby the Hard Way, and Learn C the Hard Way. He is also the creator of several open source software projects like ...
In Part 2, you learn about concurrency utilities basics and executors, synchronizers, the Locking Framework, and the additional capabilities of concurrent collections, atomic variables, and the Fork/...
The Objective-C class reference documentation alone would fill thousands of printed pages, not to mention all the other tutorials and guides included with Xcode. Where do you start? Which classes are...
The Essential Guide to HTML5 and CSS3 Web Design provides a modern, integrated approach to web design. Each of the chapters looks at a specific aspect of creating a web page, such as formatting type, ...