html - 带边框的倾斜 div
问题描述
我有这个代码,其中有 6 个倾斜的 div。我想要做的只是给中心标题 2 div 提供黑色边框,但是当我给它提供边框时,它只显示顶部和底部。左右边框不可见。
.title {
background: #f2f2f2;
}
.img {
min-height: 300px;
background: center/cover no-repeat;
}
.col:first-child {
clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 0 100%);
margin-right: -5vw;
}
.col:nth-child(2) {
clip-path: polygon(10vw 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 15px 100%);
margin: 0 -5vw;
}
.col:last-child {
clip-path: polygon(10vw 0, 100% 0, 100% 100%, 15px 100%);
margin-left: -5vw;
}
.col:nth-child(2)>.title,
.col:last-child>.title {
padding-left: calc(10vw - 15px)!important;
}
.black-border{
border: 2px solid black;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row text-center">
<div class="col">
<div class="title p-3">Title 1</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
</div>
<div class="col">
<div class="title p-3 black-border">Title 2</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
</div>
<div class="col">
<div class="title p-3">Title 3</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
</div>
</div>
</div>
解决方案
使用drop-shadow
过滤器在元素周围添加边框:
.title {
background: #f2f2f2;
}
.filter {
--b:2px;
filter:
drop-shadow(var(--b) 0px 0px black)
drop-shadow(0px var(--b) 0px black)
drop-shadow(calc(-1*var(--b)) 0px 0px black)
drop-shadow(0px calc(-1*var(--b)) 0px black)
}
.img {
min-height: 300px;
background: center/cover no-repeat;
}
.col:first-child {
clip-path: polygon(0 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 0 100%);
margin-right: -5vw;
}
.col:nth-child(2) {
clip-path: polygon(10vw 0, calc(100% - 15px) 0, calc(100% - 10vw) 100%, 15px 100%);
margin: 0 -5vw;
}
.col:last-child {
clip-path: polygon(10vw 0, 100% 0, 100% 100%, 15px 100%);
margin-left: -5vw;
}
.col:nth-child(2)>.title,
.col:last-child>.title {
padding-left: calc(10vw - 15px)!important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<div class="container-fluid mt-2">
<div class="row text-center filter">
<div class="col">
<div class="title p-3">Title 1</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1012/800/800)"></div>
</div>
<div class="col">
<div class="title p-3 black-border">Title 2</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1015/800/800)"></div>
</div>
<div class="col">
<div class="title p-3">Title 3</div>
<div class="img mt-3" style="background-image:url(https://picsum.photos/id/1016/800/800)"></div>
</div>
</div>
</div>
推荐阅读
- python - 使用 Pandas,如何使用 float_format 修复 .sum().sum() 的格式
- .net - 使用 VB.NET 将渐变圆绘制到 PictureBox 中
- java - 我的带有 openCV 的 java 项目,不使用 .jar 在 IDE 之外加载库
- javascript - 如何从类组件中的 reactjs 中的参数获取 id?
- javascript - 如何在不同时区将日期字符串转换为 javascript 中的数据?
- javascript - 作为道具传递下来的onClick方法没有执行
- linux - 如何在使用 tmux 时将文本从一个 vi 文件复制到另一个 vi 文件
- file - 使用 cypress-file-upload 使用 Cypress 上传 xlsx 文件
- python - Numpy 操作
- ios - 如何将证书添加到 iOS 应用沙盒中