css 鼠标悬停时显示图像叠加效果
时间:2023年10月07日
/来源:网络
/编辑:佚名
悬停时显示图像叠加效果。
鼠标悬停时显示图像叠加效果
分别将 和 伪元素用于叠加层的顶部和底部栏。设置它们的,并产生所需的效果。 :before:afteropacitytransformtransition
将 用于叠加的文本。设置 ,并将文本居中到图像中。 <figcaption>display: flexflex-direction: columnjustify-content: center
使用伪选择器更新所有元素的 和并显示叠加。 :hoveropacitytransform
<figure class="hover-img">
<img src="https://picsum.photos/id/200/440/320.jpg"/>
<figcaption>
<h3>Lorem <br/>Ipsum</h3>
</figcaption>
</figure>
.hover-img {
background-color: #000;
color: #fff;
display: inline-block;
margin: 8px;
max-width: 320px;
min-width: 240px;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
.hover-img * {
box-sizing: border-box;
transition: all 0.45s ease;
}
.hover-img:before,
.hover-img:after {
background-color: rgba(0, 0, 0, 0.5);
border-top: 32px solid rgba(0, 0, 0, 0.5);
border-bottom: 32px solid rgba(0, 0, 0, 0.5);
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: '';
transition: all 0.3s ease;
z-index: 1;
opacity: 0;
transform: scaleY(2);
}
.hover-img img {
vertical-align: top;
max-width: 100%;
backface-visibility: hidden;
}
.hover-img figcaption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
align-items: center;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: center;
line-height: 1.1em;
opacity: 0;
z-index: 2;
transition-delay: 0.1s;
font-size: 24px;
font-family: sans-serif;
font-weight: 400;
letter-spacing: 1px;
text-transform: uppercase;
}
.hover-img:hover:before,
.hover-img:hover:after {
transform: scale(1);
opacity: 1;
}
.hover-img:hover > img {
opacity: 0.7;
}
.hover-img:hover figcaption {
opacity: 1;
}
鼠标悬停时显示图像叠加效果
分别将 和 伪元素用于叠加层的顶部和底部栏。设置它们的,并产生所需的效果。 :before:afteropacitytransformtransition
将 用于叠加的文本。设置 ,并将文本居中到图像中。 <figcaption>display: flexflex-direction: columnjustify-content: center
使用伪选择器更新所有元素的 和并显示叠加。 :hoveropacitytransform
<figure class="hover-img">
<img src="https://picsum.photos/id/200/440/320.jpg"/>
<figcaption>
<h3>Lorem <br/>Ipsum</h3>
</figcaption>
</figure>
.hover-img {
background-color: #000;
color: #fff;
display: inline-block;
margin: 8px;
max-width: 320px;
min-width: 240px;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
.hover-img * {
box-sizing: border-box;
transition: all 0.45s ease;
}
.hover-img:before,
.hover-img:after {
background-color: rgba(0, 0, 0, 0.5);
border-top: 32px solid rgba(0, 0, 0, 0.5);
border-bottom: 32px solid rgba(0, 0, 0, 0.5);
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
content: '';
transition: all 0.3s ease;
z-index: 1;
opacity: 0;
transform: scaleY(2);
}
.hover-img img {
vertical-align: top;
max-width: 100%;
backface-visibility: hidden;
}
.hover-img figcaption {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
align-items: center;
z-index: 1;
display: flex;
flex-direction: column;
justify-content: center;
line-height: 1.1em;
opacity: 0;
z-index: 2;
transition-delay: 0.1s;
font-size: 24px;
font-family: sans-serif;
font-weight: 400;
letter-spacing: 1px;
text-transform: uppercase;
}
.hover-img:hover:before,
.hover-img:hover:after {
transform: scale(1);
opacity: 1;
}
.hover-img:hover > img {
opacity: 0.7;
}
.hover-img:hover figcaption {
opacity: 1;
}
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03