tags:

views:

31

answers:

3

is there a way I can stop the opacity from affecting my links text when the mouse pointer hovers over my link? I just want the opacity to affect the image only.

Here is the CSS.

.email {
    background: url(../images/email.gif) 0px 0px no-repeat;
    margin: 0px 0px 0px 0px;
    text-indent: 20px;
    display: inline-block;
}

.email:hover {
    opacity: 0.8;
}

Here is the xHTML.

<a href="#" title="Email" class="email">Email</a>
+1  A: 

Short answer: No.

Long answer: Yes, if you use rgba colors instead of the opacity property. For example, the following would give you a black background with 20% opacity, and black text with full opacity:

p {
    background: rgba(0, 0, 0, 0.2);
    color: #000000;
}

For background images, use a PNG with alpha channels.

You
You should note that this is a CSS3 feature, and it not fully browser compatible. At least be aware and gracefully degrade.
Dustin Laine
A: 

Not with a background image (you can if it's just a background color). Instead of using opacity, replace the background image with less opaque version in .email:hover.

Mark Trapp
A: 

Yes, take the text out of the context of the transparent container with absolute positioning. This will work with background images as well!

<div id="TransContainer">
    <div id="TransBox" href="#">Some text that will be opaque!</div>
    <div id="NonTransText">Some text that I do not want opaque!</div>
</div>

<style>
#TransContainer
{
    position: relative;
    z-index: 100;
    display: block;
    width: 420px;
    height: 165px;
    background-color: blue;
}
#TransBox
{
    background-color: green;
    display: block;
    width: 100px;
    height: 100px;
    opacity:0.4;
    filter:alpha(opacity=40)
}
#NonTransText
{
    color: #000;
    position: absolute;
    top: 20px;
    left: 0;
}
</style>
Dustin Laine
Horrible solution to a problem that doesn't exist.
You
It very much does exist in any browser that is not compatible with CSS3. I do agree that with CSS3, your solution is by far the best.
Dustin Laine