Gar*_*eth 43
id s id entify elements.class es class ify elements.
如果"它是一种......"(例如地址),就在一个元素上放一个类
把一个ID,如果一个元素"是的 ......"(如导航)
cle*_*tus 10
你按照这个偏好顺序去:
ID是迄今为止最快的查找.下一个最快的是按标记名查找.最慢的是按类名.
至于何时使用类或ID,可以在可能的情况下使用ID,在不能的时候使用类.
每页打算使用一次ID.我使用ID来指定主要布局元素
<div id="mainForm">
<div id="wrapper">
Run Code Online (Sandbox Code Playgroud)
类可以跨多个元素定义样式.我用它来定义某种类型元素在页面上的显示方式.
<p class="comments">
<div class="smallText">
Run Code Online (Sandbox Code Playgroud)