2008年3月12日 星期三

id and class

class
different elements can share the same class:
when you want to apply attribute to many elements, use class
an element can belong to many classes
ex: h1 class="red", h2 class="red"

how to define the class:
ex: p.green{
color: green;
}
class name is green. It only apply to p

ex: .green
class name is green. It can apply to all elements

id
id is for only one element
when you want to apply attribute to an unique element, use id
an element can only have one id
an element can have one id and belong to many classes
ex: error: h1 id= "red" , h2 id ="red"
error: p id ="red" , p id = "red"

how to define the id
ex: #test {
color: green;
}
id name is test, It can apply to all elements

p#test {
color: green
}
id name is test, it can only apply to p element

沒有留言: