Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to inherit attributes in CSS class?

Status
Not open for further replies.

redsss

Programmer
Mar 17, 2004
72
US
I want to change a DHTML button when the mouse rolls over by changing the class, like so:
Code:
<div class="normalclass" 
 onMouseover="this.className='hoverclass'"
 onMouseout="this.className='normalclass'" >Testing</div>

So my normal class has several attributes like

Code:
.normalclass 
{
 margin-bottom: 5px;
 background-color:yellow;
 color:red;
 width:130px;
}

and I want my hoverclass to inherit all those attributes of the normal class so that I only need to override certain attributes, like so:

Code:
.hoverclass {
background-color:green;
}

How do I make .hoverclass inherit the attributes of .normalclass?
 
One way
Code:
.normalclass, .hoverclass
{
 margin-bottom: 5px;
 background-color:yellow;
 color:red;
 width:130px;
}
followed by
Code:
.hoverclass {
background-color:green;
}

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Another way is to use the :hover pseudo class. If you need to cater for IE, you will have to use it with <a> element, but sometimes that is not unacceptable:
Code:
a.special {
 display: block;
 margin-bottom: 5px;
 background-color: yellow;
 color: red;
 width: 130px;
}

a.special:hover {
 background-color: green;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top