CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 24th, 2003, 08:31 PM
Cira9999 Cira9999 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 226 Cira9999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 38 m 41 sec
Reputation Power: 6
css inheritance - best practices

This is probably a very basic question for someone who has been working with styles for years, so I apologize in advance.

Here are three styles for 3 different buttons:
Code:
INPUT.buttons {	
	font-family: Tahoma, Verdana, Arial;
	color: #FFFFFF;
	font-size: 11px;
	font-weight: bold;
	border-style: solid;
	border-color: #666666;
	border-width: 1px;
	background-color: #748196;
	cell-spacing: 4px;
	width: 70px;
}

INPUT.smallbuttons {	
	font-family: Tahoma, Verdana, Arial;
	color: #FFFFFF;
	font-size: 11px;
	font-weight: bold;
	border-style: solid;
	border-color: #666666;
	border-width: 1px;
	background-color: #748196;
	cell-spacing: 4px;
	width: 30px;
}

INPUT.longbuttons {	
	font-family: Tahoma, Verdana, Arial;
	color: #FFFFFF;
	font-size: 11px;
	font-weight: bold;
	border-style: solid;
	border-color: #666666;
	border-width: 1px;
	background-color: #748196;
	cell-spacing: 4px;
	width: 120px;
}


The only difference between the 3 styles is the width. It seems like bad practice to have to declare all the other elements that the 3 styles have in common, 3 times.

I'm wondering what is the best way to handle this. In theory I'd like my code be something like this:
Code:
INPUT.buttons {	
	font-family: Tahoma, Verdana, Arial;
	color: #FFFFFF;
	font-size: 11px;
	font-weight: bold;
	border-style: solid;
	border-color: #666666;
	border-width: 1px;
	background-color: #748196;
	cell-spacing: 4px;
}

INPUT.smallbuttons { width: 30px; }
INPUT.longbuttons { width: 120px; }


and have the latter two styles inherit the "buttons" class style.
I do this with other styles for example:
Code:
INPUT {
	font-family: Tahoma, Verdana, Arial;
	font-size: 11px;
	color: #333333;
	border-top: #666666 1px outset;
	border-left: #666666 1px outset;
	border-bottom: #666666 1px inset;
	border-right: #666666 1px inset;
	background-color: #FFFFFF;
	width: 85px;
}
INPUT.prefix { width: 22px; }
INPUT.suffix { width: 27px; }


but that makes sense because I'm declaring a style for ALL input tags and then the classes inherit the INPUT's elements, overriding the width.

Also, I don't want to override the style in the HTML like this:

<input class="buttons" style="width: 10px"....

nor do I want to use JavaScript to dynamically set the width.

How do I do this?

Thanks,
__________________
-Samantha

Reply With Quote
  #2  
Old November 24th, 2003, 10:14 PM
Winters Winters is offline
Bad Coder
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2003
Posts: 1,744 Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level)Winters User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 12 h 2 m 26 sec
Reputation Power: 171
Hope this helps.
Attached Files
File Type: html buttonstyles.html (574 Bytes, 181 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > css inheritance - best practices


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway