我有一组带有背景图像的框,并以文本为中心。当您将鼠标悬停在框上时,图像缩放和动画会正常工作,但文本仅在您将鼠标直接悬停在框上而不是框本身时才会消失。
* {
box-sizing: border-box;
}
body {
background-color: rgb(236, 237, 229);
}
.wrapper {
max-width: 960px;
padding: 50px 50px;
max-width: 1200px;
text-align: center;
margin: 40px auto;
}
.parent {
overflow: hidden;
display: inline-block;
cursor: pointer;
width: 430px;
height: 300px;
margin: 0 20px 60px 20px;
}
.child {
background-size: cover;
background-position: center;
background-repeat: no-repeat;
transform: scale(1.2);
width: 100%;
height: 100%;
transition: all .5s;
display: flex;
}
.child a {
font-size: 1.2rem;
font-family: 'Open Sans', sans-serif;
letter-spacing: .4em;
overflow: hidden;
cursor: pointer;
text-decoration: none;
text-transform: uppercase;
margin: auto;
color: #fff;
border: 2px solid;
text-shadow: 2px 4px 3px rgba(0, 0, 0, 0.6);
padding: 5px;
font-weight: 900;
}
.child a:hover {
opacity: 0;
}
.child:hover {
transform: scale(1);
}
<div class="wrapper">
<div class="parent">
<div class="child bg_boats">
<a href="#">Boats</a>
</div>
</div>
<div class="parent">
<div class="child bg_hats">
<a href="#">Hats</a>
</div>
</div>
<div class="parent">
<div class="child bg_coffeeflowers">
<a href="#">Coffee & flowers</a>
</div>
</div>
<div class="parent">
<div class="child bg_crystals">
<a href="#">Crystals</a>
</div>
</div>
</div>
我是编程新手,我遇到的唯一解决方案是使.child 成为内联块元素,然后去掉边框并应用填充。然而,这看起来很乱,文本显示错误。
.child:hover a {
opacity: 0;
}
如果您希望将鼠标悬停在框上时文本消失,请将选择器更改为.child:hover a
。这将选择悬停在元素上的任何<a>
标签.child
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句