CSS 用于创建不旋转的倾斜正方形的样式
CSS Styling to create a slanted square without rotate
我正在尝试创建这个:
Image with slanted square overlay
我无法稍微倾斜。我可以通过更改边框来实现三角形,但是它倾斜太多了。
这是我的带有正方形和文本的图像的代码:
.realtor-img-background {
height: 400px;
width: 450px;
background: url("./images/real-estate.jpg");
}
.square{
position: absolute;
bottom:0;
height: 200px;
width: 450px;
background-color: red;
}
<div class="realtor-img-background">
<div class="square">
<h3 class="eva-text-white">
Realtors
</h3>
<p class="eva-text-white">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
</div>
</div>
您可以在 Border
的帮助下使用 CSS 伪元素创建此形状
.realtor-img-background {
height: 400px;
width: 450px;
position: relative;
background: url("http://via.placeholder.com/350x150") no-repeat top center;
background-size: cover;
}
.square {
position: absolute;
bottom: 0;
background-color: red;
}
.square:before {
content: "";
position: absolute;
left: 0;
top: -100px;
border-style: solid;
z-index: 1;
width: 0;
height: 0;
border:0;
border-bottom: 100px solid red;
border-right: 450px solid transparent;
}
<div class="realtor-img-background">
<div class="square">
<h3 class="eva-text-white">
Realtors
</h3>
<p class="eva-text-white">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
</div>
</div>
我正在尝试创建这个:
Image with slanted square overlay
我无法稍微倾斜。我可以通过更改边框来实现三角形,但是它倾斜太多了。
这是我的带有正方形和文本的图像的代码:
.realtor-img-background {
height: 400px;
width: 450px;
background: url("./images/real-estate.jpg");
}
.square{
position: absolute;
bottom:0;
height: 200px;
width: 450px;
background-color: red;
}
<div class="realtor-img-background">
<div class="square">
<h3 class="eva-text-white">
Realtors
</h3>
<p class="eva-text-white">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
</div>
</div>
您可以在 Border
的帮助下使用 CSS 伪元素创建此形状.realtor-img-background {
height: 400px;
width: 450px;
position: relative;
background: url("http://via.placeholder.com/350x150") no-repeat top center;
background-size: cover;
}
.square {
position: absolute;
bottom: 0;
background-color: red;
}
.square:before {
content: "";
position: absolute;
left: 0;
top: -100px;
border-style: solid;
z-index: 1;
width: 0;
height: 0;
border:0;
border-bottom: 100px solid red;
border-right: 450px solid transparent;
}
<div class="realtor-img-background">
<div class="square">
<h3 class="eva-text-white">
Realtors
</h3>
<p class="eva-text-white">
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.
</p>
</div>
</div>