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
Changing One Attribute of a Class?
Old 03-14-2009, 06:56 AM Changing One Attribute of a Class?
Ultra Talker

Posts: 316
Trades: 0
Say if I have a class like this:

.middle {
width: 60%;
color: red;
}

But I want to apply if to a DIV but I want the width to be 100%

Can I do that (and if so how) or do I have to create a new class?

Thanks.
Joe3000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-14-2009, 07:03 AM Re: Changing One Attribute of a Class?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
BTW A div will be 100% if you don't apply any CSS rules to it.

set a new rule specifically for div elements with class "middle" that will override the properties in the global class

Code:
div.middle {
   width:100%;
}
so a div with class "middle" will have all the rules in "middle" applied apart from the width.
ensure the div rule is after the global in the stylesheet hierarchy
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-14-2009, 07:18 AM Re: Changing One Attribute of a Class?
Ultra Talker

Posts: 316
Trades: 0
The thing is, they are both DIVS and then I have other styles like .middle h1, .middle a:link etc

If I created a new class and apply it to the DIV it won't get all the styles from .middle h1, .middle a:link etc and I will have to create div.middle h1, div.middle a:link etc

Is that correct?
Joe3000 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2009, 07:26 AM Re: Changing One Attribute of a Class?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
elements can have multiple classes defined in a space delimited list:
eg:
HTML Code:
<div class="middle mid_full_width">
Code:
.mid_full_width{
   width:100%;
}
then that div will then have rules for "middle" and all the "middle" cascading rules plus the overrides from "mid_full_width"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-14-2009, 09:15 AM Re: Changing One Attribute of a Class?
Ultra Talker

Posts: 316
Trades: 0
Thanks that is perfect.
Joe3000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing One Attribute of a Class?
 

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 0.35340 seconds with 12 queries