我目前正在尝试为网站创建一个特殊的悬停。
以下是我要做的事情:
4个区块,所有区块都响应黑色条形,主要文本的不透明度为70%。
然后当我悬停一个区块时,黑色条填满底部的所有空间并显示2或4个按钮。
也许是这样的:
<div class="image-block">
<div class="image1">
<span class="black-bar">SOME TEXT</span>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
<div class="image2">
<span class="black-bar">SOME TEXT</span>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
<div class="image3">
<span class="black-bar">SOME TEXT</span>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
<div class="image4">
<span class="black-bar">SOME TEXT</span>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
</div>
但对于CSS,我真的不知道如何做到这一点。用完全响应的东西做最简单最好的方法是什么?
谢谢!
答案 0 :(得分:1)
查看下面的代码(我必须使用jQuery)或this fiddle
$('.text').mouseenter(function () {
$('.hovering').animate({'height': '200px'}, 'slow');
});
$('.image').mouseleave(function () {
$('.hovering').animate({'height': '100px'}, 'slow');
});
&#13;
.image {
position: relative;
background-image: url(http://www.w3schools.com/css/trolltunga.jpg);
height: 300px;
width: 600px;
}
.hovering {
display: block;
height: 100px;
width: 600px;
background-color: rgba(0,0,0,0.7);
overflow: hidden;
margin-top: 100px;
position: absolute;
}
button, .text {
display: block;
width: 130px; height: 40px;
margin: 0 auto;
}
.text {
color: white;
font-size: 40px;
text-align: center;
padding-top: 30px;
width: 200px;
margin-bottom: 30px;
display: block;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image">
<div class="hovering">
<span class="text">Text here</span>
<button>Button here</button>
</div>
</div>
The black box shrinks when mouse leaves the image
&#13;
答案 1 :(得分:1)
这是一个纯css
选项。如果我错过了什么,请告诉我。我不得不稍微调整你的标记。
.image-block{
display: flex;
flex-direction: row;
}
.col{
display: flex;
flex-direction: column;
}
.image1, .image2, .image3, .image4{
background: url(http://lorempixel.com/output/nature-q-c-640-480-1.jpg) no-repeat center center;
background-size: cover;
width: 200px;
margin: 0 20px 20px 0;
position: relative;
overflow: hidden;
}
.image1, .image4{
height: 100px;
}
.image2, .image3{
height: 200px;
}
.black-bar{
background: rgba(0,0,0,0.4);
text-align: center;
color: #fff;
width: 100%;
top: 50%;
position: absolute;
margin-top: -18px;
padding: 10px 0;
font-family: Helvetica, Arial, sans-serif;
transition: all 0.5s ease;
bottom: calc(50% - 15px);
overflow: hidden;
}
.black-bar button{
margin: 10px;
display: none;
border: none;
background: #fff;
}
.black-bar p{
margin: 0;
font-weight: 200;
font-size: 12px;
}
.image1:hover .black-bar, .image2:hover .black-bar, .image3:hover .black-bar, .image4:hover .black-bar{
bottom: 0;
transition: all 0.5s ease;
}
.image1:hover .black-bar button, .image2:hover .black-bar button, .image3:hover .black-bar button, .image4:hover .black-bar button{
display: inline-block;
}
&#13;
<div class="image-block">
<div class="col">
<div class="image1">
<div class="black-bar">
<p>SOME TEXT</p>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
</div>
<div class="image2">
<div class="black-bar">
<p>SOME TEXT</p>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
</div>
</div>
<div class="col">
<div class="image3">
<div class="black-bar">
<p>SOME TEXT</p>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
</div>
<div class="image4">
<div class="black-bar">
<p>SOME TEXT</p>
<button class="special-button">Button</button>
<button class="special-button">Button</button>
</div>
</div>
</div>
</div>
&#13;
修改强>
通过calc
魔法的一点点添加动画。
bottom: calc(50% - 15px);