html - 使用带跨度的过渡?
问题描述
当我将鼠标放在图像上时,我试图显示居中的文本。我找到了一种使用 Span 的方法,但是过渡不起作用。有人可以帮我吗?是否有其他方法可以制作“过度居中的 txt”?
这是代码:
body {
margin: 0;
padding: 0px;
overflow-x: hidden;
font-family: Arial, Helvetica, sans-serif;
background-color: #000000;
;
text-align: center;
}
#content {
padding-top: 71px;
transition-duration: 1s;
}
#content a {
width: 800px;
display: inline-block;
position: relative;
text-decoration: none;
transition: 1s
}
#content a img {
border: none;
width: 100%;
transition: 1s
}
#content a span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
}
#content a:hover span {
display: block;
}
#content span.title {
display: none;
color: #FFF;
font-weight: bold;
font-size: 1.2em;
z-index: 2;
transition: 1s;
}
#content span.bg {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 100%;
width: 100%;
background: black;
transition: 1s;
opacity: 0.5;
}
<div id="content">
<a href="#">
<span class="title">Mon titre</span>
<span class="bg"></span>
<img src="B 1.jpg" alt="" />
</a>
</div>
<div id="footer">
</div>
这是我使用的示例的来源
解决方案
据我所知,您不能在显示属性上使用过渡。为什么你不使用不透明度来代替?做这样的事情
#content a span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity : 0;
transition : opacity 1s ease-in-out;
}
#content a:hover span {
opacity:1;
}
并删除其他显示和过渡。
推荐阅读
- javascript - 服务器崩溃,重启时发送消息(Node.js / Socket.io)
- c++ - 如何包装第 3 方 DLL 以在 R 中使用?
- angular - 构造函数注入影响基本测试问题
- python - 如何在使用 selenium python 隐藏锚标记href属性时获取它
- xcuitest - XCUITest - 如何访问 XCUITest 中的应用设备令牌以触发推送通知,但无需在应用代码中设置任何 UIView?
- ruby-on-rails - has_many :通过一次调用在连接表中添加额外的参数(对象创建)
- python - Matplotlib:脚本等待“输入()”时无法操作绘图
- excel - 进行组合并检查每个可行的组合
- session - Redis Sentinel,Standalone 还是 Cluster,哪个最适合 session?
- sql-server - 连接到不同的服务器并使用批量插入