467,161 Members | 1,104 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 developers. It's quick & easy.

Div references in CSS

What is the difference between "#divname" and "div#divname"? When do you use which? I think I've seen "div.divname" too.

Thank you.
Apr 8 '07 #1
  • viewed: 1249
Share:
4 Replies
temat
# <- when using reference by id
. <- by class name

ex:
[HTML]div.#site {..} for <div id="site">...</div>
div.box {...} for <div class="box">..</div>[/HTML]

or box in site :
[HTML]div.#site.box {..} for
<div id="site"><div class="box">..</div></div>[/HTML]
Apr 9 '07 #2
temat
# <- when using reference by id
. <- by class name
<- reference to tag name [div,tr,td,....]
ex:
[HTML]
<style>
// all div tags will have font size 80%;
div { font-size:80%; }
//object with id = site will have orange fonts
#site { color:orange;}
//object with class name=box will have blue backgrounds
.box { background-color:blue; }
//only .box in #site will have blue background
#site.box { background-color:blue; }
//only box in div tag will have blue background
div.box { background-color:blue; }
//only box in div tag and id=site will have blue background
div.#site.box { background-color:blue; }
</style>
<div id="site">
<div class="box">[something]</div>
</div>
<div class="box">[something else]</div>
<span class="box">[text]</span>
[/HTML]
Apr 9 '07 #3
Expert 1GB
You can use <div class="clsClassName">...</div> as much as you want, but from my understanding id only once.
Apr 9 '07 #4
drhowarddrfine
Expert 4TB
You can use 'div#idname' or '#name' whichever you prefer. Some people prefer the 'div' or other element prefix so they are reminded what type of element the id refers to. Same when using class names.
Apr 10 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Tom | last post: by
22 posts views Thread by xmp333@yahoo.com | last post: by
33 posts views Thread by JKop | last post: by
11 posts views Thread by codebloatation@gmail.com | last post: by
14 posts views Thread by el_sid | last post: by
30 posts views Thread by jeremygetsmail@gmail.com | last post: by
3 posts views Thread by DonJefe | last post: by
9 posts views Thread by igor.kulkin@gmail.com | last post: by
3 posts views Thread by CenturionX | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.