简体   繁体   中英

Showing Text When Hovering Over an Image Link

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.

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
}

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;
}

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"?

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/

Demo

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM