Black transparent overlay on image

I am trying to get a light black overlay on the image when you hover over it (like text), sorry I'm new to css and HTML!

help would be appreciated

Html

<div id="con">
   <div id="box1">
      <p id="text1">
         <a href="url">DESTINATIONS</a>
      </p>
      </p>
      <p id="text2">
         AMALFI<BR>SORRENTO<BR>POSITANO</a>
      </p>

      <p id="text3">
         <a href="url">THINGS TO DO</a>
      </p>
      </p>
      <p id="text4">
         TOURS<BR>MUSUEMS<BR>SHOPPING</a>
      </p>
</div>

      

CSS

#con {
   width:1024px;
   height:670px;
   background-color: #161717;
}


#box1 {
   float: left;
   font-size: 25px;
   width: 388px;
   height: 477px;

   background-image: url(media/trying1.png);
   background-size: cover;
   margin-left: 120px;
   margin-top: 90px;
}


#text1 {
   z-index:100;
   color:white;
   font-size:30px;
   text-align: center; 
   margin-top:80px;
   line-height:55px;
   opacity: 0;
   transition: all 0.5s;
}

#box1:hover #text1 {
   opacity: 1;
}   

      

+3


source to share


2 answers


This can be done with: before or: after

#box1{
  position:relative;
}

#box1:before{
    content:'';
    position:absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    background:black;
    opacity:0;
    z-index:0;

}

#box1:hover:before{
 opacity:.6;   
 transition: all 0.5s;
}

#box1 > *{
    position:relative;
    z-index:1;
}

      



http://jsfiddle.net/4bo4zju7/3/

+4


source


CS3 is great! You don't need JS for simple rollover effects anymore. Gopalraju on the code should work and my example is below. You can have a fiddle with it and use the code as you see fit.

The parent div, has a black page background, and the imgdiv changes everything inside it to 50% opacity on the mouse, rolling over the div. In this case, the image is inside a div.

There are several ways to do this. It's just another way to advertise. Good luck.



.parentdiv {
    background-color:#000;
    height:100%;
    width:100%;
    }

    .imgdiv {
      padding:30px;
    }

    .imgdiv a{
    	opacity: 1;
    	filter: alpha(opacity=100);
     	-webkit-transition: opacity 0.5s linear;
    }

    .imgdiv a:hover {
    	opacity: 0.5;
    	filter: alpha(opacity=50);
     	-webkit-transition: opacity 0.5s linear;
    }
      

<div class="parentdiv">
  <div class="imgdiv">
    <a href="http://www.domain.com.au/link.html">
      <img src="http://placehold.it/350x150" alt="image" height="150" width="350">
    </a>
  </div>
</div>
      

Run codeHide result


+1


source







All Articles