View Full Version : div.whythefullstop

02-22-2011, 11:54 PM

I have been playing around with loads of css scripting? or coding? not sure which term to use, however i can't seem to understand why there is the need of the full stop after some of the div id's?

such as div.ex does this select some other tag after the div id?

02-23-2011, 12:28 AM
The period denotes a class selector, not ID.

#whatever {…}
.whatever {…}

<div id="whatever"></div>
<div class="whatever"></div>

Two different things.
But you can also combine both:

<div id="whatever1" class="whatever"></div>
<div id="whatever2" class="whatever"></div>

.whatever {…}
.whatever#whatever1 {…}
#whatever2.whatever {…}

02-23-2011, 12:36 AM
Thank you for your help, appreciate it.

I need more practice in using id's and class.

02-23-2011, 12:38 AM
Be aware that an ID must be unique in an HTML document, no more than one element can have a particular ID. Classes, however, can be assigned to multiple elements on the same page.

02-23-2011, 12:41 AM
I guess an image is ideal for an id and a paragraph of text in numerous div's would be more suitable as a class.

02-23-2011, 02:04 AM
There is no general rule for that, it all depends on the context. Sometimes you don’t need any class or ID at all as you can use the element or attribute selector (e. g. p img {…}, #content > img {…} or input[type=text] {…}).