hover给图片加遮罩

61 篇文章 5 订阅
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>hover给图片加遮罩</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
.picbox {
    width: 100%;
    height: 0;
    padding-bottom: 133%;
    float: left;
    position: relative;
    margin-bottom: 8px;
}
.picbox img {
    max-width: 100%;
    height: auto;
    position: absolute;
    left: 0;
    top: 0;
}
.picbox:hover .video {
    display: block;
}
.video{
    position: relative;
    top: -70px;
    display: none;
}
</style>
</head>
<body>
<div class="picbox">
<img src="44.jpg" alt="123">
<img class="video" src="video.png" alt="">
</div> 
</body>
</html>
可以使用以下的HTML和CSS代码来实现图片底部透明遮罩文字标题: HTML代码: ```html <div class="image-container"> <img src="your-image-url" alt="your-image-alt-text"> <div class="overlay"> <h2>Your Title Here</h2> </div> </div> ``` CSS代码: ```css .image-container { position: relative; display: inline-block; overflow: hidden; } .image-container img { display: block; width: 100%; height: auto; } .overlay { position: absolute; bottom: 0; left: 0; width: 100%; background-color: rgba(0, 0, 0, 0.6); color: #fff; padding: 10px; box-sizing: border-box; transition: all 0.3s ease; } .overlay h2 { margin: 0; } .image-container:hover .overlay { transform: translateY(-100%); } ``` 解释一下: 首先,我们使用一个 `div` 元素作为图片容器,并设置其为相对定位。接着,我们在容器内部放置一个 `img` 元素用于显示图片,并设置其为块级元素,宽度为100%,高度自适应。 接下来,我们再在容器内部放置一个 `div` 元素,用于显示标题。我们将其设置为绝对定位,底部对齐,左侧对齐,宽度为100%,背景颜色为半透明黑色,文字颜色为白色,内部添10px的内边距,并设置盒模型为 `box-sizing: border-box`,以便于我们在设置内边距时不会影响元素的实际宽度。 最后,我们使用CSS3的过渡效果,当鼠标悬停在容器上时,将标题向上移动,露出图片底部的部分,从而实现了透明遮罩效果。 需要注意的是,以上CSS代码中的 `rgba(0, 0, 0, 0.6)` 表示半透明黑色,其中最后一个参数 `0.6` 可以根据需要进行调整。同时,需要将代码中的 `your-image-url` 和 `your-image-alt-text` 替换为实际的图片 URL 和替代文本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林中明月间。

分享共赢。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值