html - 图像悬停后尝试显示内容

标签 html css

只是为了我的一个元素从头开始制作这个。我想在图像上创建悬停效果,然后在顶部显示有关该图像的内容。图像会在悬停时变暗,然后内容会显示在图像上方。

我遇到的问题是内容超出了其父 div 的不透明度。如何使子 div 不受不透明度属性的影响?

这是我的 HTML:

<div class="featured-home-bg">
            <div class="background-content">
                <div class="featured-home-content">
                    <h2>Home Name</h2>
                    <p>Lorem Ipsum leo dormit tan loius ov noetermit.</p>
                </div><!--- end featured-home-content --->
            </div><!--- end background-content --->
</div><!--- end featured-home-bg --->

这是我的 CSS:

.featured-home-bg {
    background: url(../images/home-1.jpg) no-repeat;
    background-size: 400px;
    height: 300px;
}

.background-content {
    background-color: #000;
    height: 225px;
    width: 400px;
    opacity: 0;
}

.background-content:hover {
    opacity: 0.6;
    -webkit-transition: opacity 0.50s ease-in-out;
    -moz-transition: opacity 0.50s ease-in-out;
    -ms-transition: opacity 0.50s ease-in-out;
    -o-transition: opacity 0.50s ease-in-out;
}

.featured-home-content {
    width: 400px;
    height: 300px;
}

.featured-home-content:hover {
    cursor: pointer;
    width: 400px;
    height: 300px;
}

最佳答案

这是@Henric Åkesson 所说的方法,但这里有每个 div

html

> <div class="image"><!-- image can be placed here --> <div
> class="imagehover">text </div></div>

CSS

.image {    
width: 400px;
height: 400px;
background-color: red;
line-height: 400px;
}
.imagehover{
width: 400px;
height: 400px;
background:; 
opacity:0;
text-align: center;
font-size:20px;
transition: 0.2s ease-in-out;
}
.image:hover .imagehover { 
transition: 0.2s;
opacity:1;
background-color: rgba(0, 0, 0, 0.5);
text-align:justify; 
color:white;
font-size:25px; 
font-weight:700; 
font-family: "apercu",Helvetica,Arial,sans-serif; 
text-align: center;
line-height: 400px;
} 

http://jsfiddle.net/d6yhnmnf/5/

关于html - 图像悬停后尝试显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26670041/

相关文章:

html - iFrame 视频无法在 iPhone (Safari) 上播放

javascript - url jquery Accordion 中没有主题标签

CSS 如何在悬停时更改 3 行(菜单图标)颜色

javascript - 在窗口调整大小时不要修改 body 任何元素的宽度或高度

html - 当绝对定位在小于文本 div 的父 div 内时,将文本保留在一行中的 div 中?

javascript - 为什么 onchange 函数不使用 Jquery 调用 DropDownList?

html - 导航栏下降到背景图片下方?

javascript - 中心动态高度/宽度图像到固定高度/宽度 div

animation - 分享很棒的 CSS3 技巧的地方

jquery - 图像裁剪方法不显示 "submit"