Link to home
Start Free TrialLog in
Avatar of chodoy
chodoy

asked on

CSS link hover

Hello,
I created a rule which is a colored div box with hot linked text within. I would like to make a hover action in which the surrounding div would change color. Is this possible with CSS?
Thank you.
.menubox {
	background-color: #b5ede4;
	height: 21px;
	width: 156px;
	padding-top: 10px;
	padding-left: 12px;
	font-weight: bold;
	border-bottom-width: 1px;
	border-bottom-style: solid;
	border-bottom-color: #FFF;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #91519c;
	text-decoration: none;
}

Open in new window

Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Yes.
.menubox {
        background-color: #b5ede4;
        height: 21px;
        width: 156px;
        padding-top: 10px;
        padding-left: 12px;
        font-weight: bold;
        border-bottom-width: 1px;
        border-bottom-style: solid;
        border-bottom-color: #FFF;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        color: #91519c;
        text-decoration: none;
}
 
.menubox:hover {
        background-color: #FFF;
        height: 21px;
        width: 156px;
        padding-top: 10px;
        padding-left: 12px;
        font-weight: bold;
        border-bottom-width: 1px;
        border-bottom-style: solid;
        border-bottom-color: #FFF;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        color: #91519c;
        text-decoration: none;
}
</style>

Open in new window

You could do:

.menubox:hover {
   background-color:red;
}

but it may not work in IE, only firefox
Sorry I'm wrong, never mind
Avatar of chodoy
chodoy

ASKER

Hi Jason,
I'm still missing something. When I apply the link it does not take on the appropriate style for the "menubox"

If I add a class, It then duplicates too much of the box attributes I don't want:

<div class="menubox"><a href="index.html" class="menubox">home</a></div>
The :hover attribute will change whatever element is being hovered.  So if you want the div to change, you apply the class to the div only.

If you want the link to change, then you apply the class to the link only (and change it so it matches the link CSS).

If you want the link to change the div, you're now in Javascript territory.
Avatar of chodoy

ASKER

Yes, I do want the link to change the div. Can you point me in the right direction for the javascript?
ASKER CERTIFIED SOLUTION
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial