简体   繁体   English

如何为我的此字幕添加背景效果?

[英]How can I add background effects to this Caption of mine?

I am having a bit of a problem, I have to add caption to my image which has a transparent background of opacity say 0.65 and color black, I have added a caption which has no background effects yet, help needed ASAP. 我遇到了一个问题,我必须为图像添加标题,该图像具有不透明的透明背景(例如0.65)和黑色,我添加了没有背景效果的标题,需要尽快提供帮助。 Thank You in advance. 先感谢您。 Here's my code 这是我的代码

 <div class="img-wrap"> <div style="300 px; font-size:20px; text-align:center;background-color= "ff0066;">
<img src="/gadgets.jpg" alt="alternate text" width="220px" height="200px" style="padding-bottom:1.0em;">
<a href="#">Gadgets and Accessories</a>
</div>
<div class="img-info">
<h3><a href="#">Gadgets & Accessories</a></h3>
<a href="#">Tablets</a><br>
<a href="#">Headphones</a><br>
<a href="#">External Optical Drives</a><br>
<a href="#">Flexible Keyboards</a><br>
<h3><a href="#">More...</a></h3>
</div>
</div>

The classes img-wrap and img-info contain styling code for some transitions for mouse hover effect, do I need to create a separate class for the caption thing? img-wrap和img-info类包含用于鼠标悬停效果的某些过渡的样式代码,我是否需要为标题内容创建一个单独的类?

I think you're looking for something like this: 我认为您正在寻找这样的东西:

FIDDLE 小提琴

Markup 标记

<div class="img-wrap">
    <img src="http://placehold.it/220x200" alt="alternate text" width="220px" height="200px" />
    <a class="caption" href="#">Gadgets and Accessories</a>
</div>

CSS CSS

.img-wrap
{
    position:relative;
    height: 200px;
    overflow:hidden;
}
.caption
{
    width:220px; 
    font-size:20px; 
    text-align:center;
    background-color: rgba(0,0,0,.7);
    position:absolute;
    left:0;
    bottom:-25px;
    color:#fff;
    visibility:hidden;
    transition: all, 0.3s ease 0.2s;
}

img
{
    width: 220px;
    height: 200px;
    display:inline-block;
}
img:hover + .caption
{
    visibility:visible;
    bottom: 2px;
    transition: all, 0.3s ease 0.2s;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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