Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Writing div.container vs .container OR div#container vs #container
Old 03-02-2011, 06:11 PM Writing div.container vs .container OR div#container vs #container
Average Talker

Posts: 24
Trades: 0
What is the difference between writing the following in a stylesheet?:

Code:
div.container
div#container
vs

Code:
.container
#container
Why write "div" in front of either? Is there something I am missing?

Last edited by EViS; 03-02-2011 at 06:12 PM..
EViS is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-02-2011, 06:19 PM Re: Writing div.container vs .container OR div#container vs #container
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,376
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The first set are rules that are tag specific and will ONLY apply to <div>ision elements. The second set could be applied to any element.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-02-2011, 06:26 PM Re: Writing div.container vs .container OR div#container vs #container
Average Talker

Posts: 24
Trades: 0
Right, so you are saying that whereas div#container rule could not be applied to a <td id="container"> element, a #container rule could be applied to a <td id="container"> element?

What are the reasons for specifying div/class/p, etc. prior to a class (.container) /div (#container) element?

Last edited by EViS; 03-02-2011 at 06:36 PM..
EViS is offline
Reply With Quote
View Public Profile
 
Old 03-02-2011, 06:35 PM Re: Writing div.container vs .container OR div#container vs #container
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,376
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by EViS View Post
I'm not quite following what you mean. Surely a div#container rule will only apply to a <div> element?
Is that not that what I said?
Quote:
Originally Posted by chrishirst View Post
The first set are rules that are tag specific and will ONLY apply to <div>ision elements.
or is using the full name of a <div> causing the confusion?
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-02-2011, 06:38 PM Re: Writing div.container vs .container OR div#container vs #container
Average Talker

Posts: 24
Trades: 0
Sorry bud, I'm dosing off here and yes that is what you said. I edited my reply straight after. Any chance you could answer the edited reply instead please ?
EViS is offline
Reply With Quote
View Public Profile
 
Old 03-02-2011, 07:18 PM Re: Writing div.container vs .container OR div#container vs #container
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,376
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by EViS View Post
Right, so you are saying that whereas div#container rule could not be applied to a <td id="container"> element, a #container rule could be applied to a <td id="container"> element
That's correct.


Quote:
Originally Posted by EViS View Post
What are the reasons for specifying div/class/p, etc. prior to a class (.container) /div (#container) element?
simply; specificity
Rules applied using the element ID (#rulename) are specific to one element and can be used to isolate rules to specific child elements in the document ie:

Code:
.warn {
/* this is a global rule set */
    color:#ff0000;
    text-decoration: blink;
}
so any element that has the <body> element as a parent with class="warn" will have flashing red text, however you can override this with;

Code:
#different .warn {
    color: #00ff00;
    text-decoration: underline; 
}
so:

HTML Code:
<body>
<span class="warn">This is red and blinking</span>

<div id="different">
<span class="warn">But this is green and underlined</span>
</div>
</body>
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-03-2011, 05:04 AM Re: Writing div.container vs .container OR div#container vs #container
Average Talker

Posts: 24
Trades: 0
Thanks for the response. I understand all of that, however your example does not specifically refer to div#container vs #container (i.e. In what instance would you write "div" infront of "#"?)

I can come up with examples for p#container (see below). However I still cannot see a reason for ever needing to write div#container?

Flashing red text anywhere inside <body>:
Code:
body {
    color:#ff0000;
    text-decoration: blink;
}
Underlined green text anywhere inside <div id="container">:
Code:
#container {
    color: #00ff00;
    text-decoration: underline; 
}
Normal blue text anywhere inside <div id="container">:
Code:
p#container {
    color: #0000ff;
    text-decoration: 0; 
}
HTML:
Code:
<body>
<p>This is red flashing text</p>
<div id ="container">
This is green underlined text
<p id="container">This is blue text</p>
</div>
</body>

Last edited by EViS; 03-03-2011 at 05:29 AM..
EViS is offline
Reply With Quote
View Public Profile
 
Old 03-03-2011, 05:41 AM Re: Writing div.container vs .container OR div#container vs #container
Average Talker

Posts: 24
Trades: 0
Right, having just watched a Lynda.com video on this, I've realised that I'm seriously over-complicating everything and I do fully understand it .

Thanks for you help pal.

Last edited by EViS; 03-03-2011 at 05:43 AM..
EViS is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Writing div.container vs .container OR div#container vs #container
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 2.53288 seconds with 12 queries