尝试实现像图片所示的效果,但不确定最佳方法,因为我想在悬停时改变div的高度。
容器div必须是100%宽度、100%高度,里面的div完全响应。
边框、伪元素或背景对于这种情况不起作用。
html
<div class="container">
<div class="top"></div>
<div class="center">
<p>text text</p>
</div>
<div class="bottom"></div>
</div>
css
.container{
width: 100%;
height: 100vh;
overflow: hidden;
// transform: skewY(-45deg);
// transform: rotate(-45deg);
}
.top, .bottom {
width: 100%;
height: calc(50% - 20px);
}
.top {
background: black;
}
.bottom {
background: grey;
}
.center {
background: green;
height: 40px;
width: 100%;
}
p {
color: white;
line-height: 10px;
text-align: center;
}
在 jsfiddle 中,您将看到旋转和skewY都已经注释。