gpt4 book ai didi

html - 如何使用具有倾斜边框装饰的相邻 div 实现双边框

转载 作者:太空狗 更新时间:2023-10-29 15:53:20 25 4
gpt4 key购买 nike

我正在尝试创建三个具有“连环画”感觉的独立容器。我希望最终结果看起来像这张图片,白色边框被黑色边界包围,并且它们之间有倾斜的分隔线:

enter image description here

这是我最接近实现此目的的一次,但是您会发现我缺少内部黑色边框。我也不确定如何在顶部和底部绘制主要的黑色边框,并允许它们中断以使白色相交。 (请在全屏模式下运行代码段):

.container {
width: 1020px;
}

.clear{clear:both; font-size:0px;line-height:0px; display:block;}

.categorycta {
border-top: 2px solid #000;
border-bottom: 2px solid #000;
background-color: #ffffff;
}

.bandtop {
content: '';
height: 10px;
background-color: #ffffff;
display: block;
border-top: 2px solid #000;
}

.bandbot {
content: '';
height: 10px;
background-color: #ffffff;
display: block;
border-bottom: 2px solid #000;
}

.categorycta .col {
position: relative;
height: 216px;
width: 340px;
float: left;
background-size: cover;
}

.categorycta .col.left:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 20px solid transparent;
border-top: 216px solid #fff;
border-left: 10px solid transparent;
border-right: 0 solid #fff;
position: absolute;
top: 0;
right: 0;
}

.categorycta .col.mid:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 216px solid #fff;
border-top: 20px solid transparent;
border-left: 0px solid transparent;
border-right: 10px solid transparent;
position: absolute;
top: -20px;
left: 0;
}

.categorycta .col.mid:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 216px solid #fff;
border-left: 10px solid transparent;
border-right: 0 solid #fff;
position: absolute;
top: -20px;
right: 0;
}

.categorycta .col.right:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 216px solid #fff;
border-bottom: 20px solid transparent;
border-left: 0px solid transparent;
border-right: 10px solid transparent;
position: absolute;
top: 0;
left: 0;
}
<div class="container">
<div class="bandtop"></div>
<div class="categorycta">
<div class="col left" style="background-image: url('http://lorempixel.com/340/220/');">

</div>
<div class="col mid" style="background-image: url('http://lorempixel.com/340/222/">
</div>
<div class="col right" style="background-image: url('http://lorempixel.com/340/225/">
</div>
<div class="clear"></div>
</div>
<div class="bandbot"></div>
</div>

最佳答案

你需要删除现有的边框,而不是你可以使用transform: skewX(2deg); 并在其周围添加黑色边框,使用margin-top 覆盖上下边框。

示例:

.container {
width: 1020px;
}

.clear{clear:both; font-size:0px;line-height:0px; display:block;}

.categorycta {
border-top: 2px solid #000;
border-bottom: 2px solid #000;
background-color: #ffffff;
}

.bandtop {
content: '';
height: 10px;
background-color: #ffffff;
display: block;
border-top: 2px solid #000;
}

.bandbot {
content: '';
height: 10px;
background-color: #ffffff;
display: block;
border-bottom: 2px solid #000;
}

.categorycta .col {
position: relative;
height: 216px;
width: 340px;
float: left;
background-size: cover;
}

.categorycta .col.left:after {
content: '';
line-height: 0;
font-size: 0;
width: 10px;
height: 102%;
/* border-bottom: 20px solid transparent; */
/* border-top: 216px solid #fff; */
/* border-left: 10px solid transparent; */
/* border-right: 0 solid #fff; */
background: white;
transform: skewX(2deg);
border-left: 2px solid black;
border-right: 2px solid black;
margin-top: -2px;
z-index: 1;
position: absolute;
top: 0;
right: -10px;
}

.categorycta .col.mid:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-bottom: 216px solid #fff;
border-top: 20px solid transparent;
border-left: 0px solid transparent;
border-right: 10px solid transparent;
position: absolute;
top: -20px;
left: 0;
}

.categorycta .col.mid:after {
content: '';
line-height: 0;
font-size: 0;
width: 10px;
height: 102%;
position: absolute;
top: 0;
right: -9px;
background: white;
transform: skewX(-3deg);
border-left: 2px solid black;
border-right: 2px solid black;
margin-top: -2px;
z-index: 1;
}

.categorycta .col.right:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 216px solid #fff;
border-bottom: 20px solid transparent;
border-left: 0px solid transparent;
border-right: 10px solid transparent;
position: absolute;
top: 0;
left: 0;
}
<div class="container">
<div class="bandtop"></div>
<div class="categorycta">
<div class="col left" style="background-image: url('http://lorempixel.com/340/220/');">

</div>
<div class="col mid" style="background-image: url('http://lorempixel.com/340/222/">
</div>
<div class="col right" style="background-image: url('http://lorempixel.com/340/225/">
</div>
<div class="clear"></div>
</div>
<div class="bandbot"></div>
</div>

关于html - 如何使用具有倾斜边框装饰的相邻 div 实现双边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46678467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com