I have the following:
<div id="side-menu" class="sidebar-nav span2">
<div class="sidebar-link"><span>Link 1</span></div>
<div class="sidebar-link"><span>Link 2</span></div>
</div>
I'm trying to make each of the two divs change color when you hover over them - whether you hover over the text of off to the right or left of the text. Currently the color changes only if I hover over the text. Any idea how this can be done? Here's my fiddle with css:
http://jsfiddle.net/PTSkR/56/
Changing link color on hover using CSS To change the color of your link on hover, use the :hover pseudo property on the link's class and give it a different color.
You'll need a container div and at least one foreground div to cover the background (could be just an image). Then you'll want to target the parent on hover and change the foreground child. I used transform instead of animating a position property because it's more performant.
You have a space in the hover selector. This matters because the space is the descendant selector in CSS
div.sidebar-link :hover{
background-color: #E3E3E3;
}
This means that only hovered descendants of .sidebar-link
are affected by the rules. Remove the space.
http://jsfiddle.net/ExplosionPIlls/PTSkR/57/
You can achieve this easily by this following code: Link
.cstDiv{
padding:10px; /* text-align:center may be used for a good look */
width:55px;
}
div.cstDiv:hover{
background-color:gray;
color:white;
cursor:pointer; /* you may delete this if you want */
}
<div>
<div class="cstDiv">Link I</div>
<div class="cstDiv">Link II</div>
<div class="cstDiv">Link III</div>
<div class="cstDiv">Link IV</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With