0

I have already looked here (How to show text on image when hovering?) to find a solution to this problem but it doesnt 100% work... Because the paragraph is located below the image part of the image is not covered when you hover over it. I want the whole image covered by the text when you hover over the image. (Look at this: http://jsfiddle.net/rMhGE/ or below.)

The HTML

<body>
        <div class="cube1">

            <a href="http://google.com"><img src="http://us.123rf.com/400wm/400/400/busja/busja1209/busja120900010/15099001-detailed-vector-image-of-symbol-of-london--best-known-british-double-decker-bus.jpg">
            <p class="contact">Random Text Here</p></a>
       </div>
</body>

The CSS

.cube1 {
    position: relative;
    width: 400px;
    height: 400px;
    float: left;
}

.contact {
    overflow: hidden;
    position: absolute;
    width: 400px;
    height: 386px;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    color: #aaa;
    visibility: hidden;
    opacity: 0;
}

.cube1:hover .contact {
    visibility: visible;
    opacity: 1;
}

Any help is appreciated. Thank you.

Community
  • 1
  • 1
roryjt
  • 5
  • 2
  • 3
  • answers already provided. but probably you should get rid of visibility and opacity and use only display. – gp. Aug 25 '13 at 04:07

5 Answers5

3

change the p {margin:0px} of the p element or give the class

.contact {
    overflow: hidden;
    position: absolute;
    width: 400px;
    height: 395px;//change height also to cover it completly
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    color: #aaa;
    visibility: hidden;
    opacity: 0;
    margin:0px
}
Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43
3

Remove the height from contact. as well as the margin. You also don't need the width value if you're stretching it with the absolute 0 0 0 0 method.

.contact {
    overflow: hidden;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255,255,255,0.95);
    color: #aaa;
    visibility: hidden;
    opacity: 0;
    margin: 0;
}
Jeffpowrs
  • 4,430
  • 4
  • 30
  • 49
0

The image has the text over it, I am not sure what you are trying to do here. What do you mean by "covering the image"?

gespinha
  • 7,968
  • 16
  • 57
  • 91
0

You need to set margin on the "p" element to 0 and the "height" to 400:

margin:0;
height:400px;

Updated jsFiddle: http://jsfiddle.net/rMhGE/5/

htxryan
  • 2,871
  • 2
  • 21
  • 21
  • 2
    And the height for the `p` element should be `400px` to match the image. – Michal Aug 25 '13 at 03:40
  • 1
    I realized that the absolute position along with 0 for top/bot/left/right was setting the height/width perfectly already, so you can get rid those outright. – Michal Aug 25 '13 at 03:44
0

Demo

Remove the height from .contact and apply top: -15px; bottom: -15px;

Alternatively, the best way, set margin: 0; removing height.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231