Jump to content

Opacity image hover issue


dweb

Recommended Posts

Hi al

 

I have the following code;

<style>
.mybox { margin-left:50px; margin-top:50px; position:relative }
.myboxtitle { position:fixed; margin-top:-120px; margin-left:20px; background-color:#CCC; padding:20px }
.mybox img:hover { opacity:0.1; }
</style>
<div class="mybox"><img src="file1.jpg" width="300" /><a><h1 class="myboxtitle">Image 001</h1></a></div>
<div class="mybox"><img src="file2.jpg" width="300" /><a><h1 class="myboxtitle">Image 002</h1></a></div>

which works well.

 

the problem is when i hover over the div (myboxtitle) the image opacity is lost

 

how can i retain the image opacity when hovering over the div (myboxtitle), but i don't want any opacity applied to the div, just the image

 

can anyone help me?

 

thanks

Edited by dweb
Link to comment
Share on other sites

Good morning,

 

It seems using rgba() instead of opacity allows you to decrease the opacity of an element while retaining the other elements opacity value.

 

Try this:

 

.mybox
{ 
        background: rgba(255,255,255, 0.5);
}
 
//background: rgba(red, green, blue, alpha) - alpha = opacity.

 

My values of 255,255,255 assumes the background colour of the .myBox div id white.

 

Change them to suit.

 

Hope this helps.

 

Kind regards,

 

cL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.