By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,677 Members | 1,807 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,677 IT Pros & Developers. It's quick & easy.

Div references in CSS

P: 7
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
Share this Question
Share on Google+
4 Replies


temat
P: 5
# <- 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
P: 5
# <- 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 100+
P: 1,892
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 5K+
P: 7,435
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.