Please answer the following questions for the two CSS example codes given in the end.
class="searchwrapper"
or should I use id="searchwrapper"
? And why, what is the difference?Example 1: Starting with #[hash]
#searchwrapper {
/*some text goes here*/
}
Example 2: Starting with .[dot]
.searchbox {
/*some text goes here*/
}
These are CSS selectors:
#foo
means an element with id foo
.foo
means all element with class foo
See http://www.w3.org/TR/CSS2/selector.html
IDs are unique, so you can only have one element with the same ID. While a class can be the same for many elements (and every element can have several classes).
.
specifies a class
#
specifies an ID
Class Example:
.myElement {...}
will match
<div class="myElement">
ID Example:
#myElement {...}
will match
<div id="myElement">
Only one element may have a particular ID, but multiple elements may share a particular class.
#
in your CSS. .
in your CSS.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With