gpt4 book ai didi

html - 倾斜或扭曲的边框形状

转载 作者:行者123 更新时间:2023-11-28 03:57:28 28 4
gpt4 key购买 nike

我对是否可以使用 CSS 创建环绕(或者更准确地说是扭曲)边框感兴趣。我要达到的效果如图。

enter image description here

最佳答案

最简单和简洁的解决方案是使用 svg 来创建边框。

enter image description here

#container {
position: relative;
width: 200px;
height: 30px;
}
#content {
text-transform: uppercase;
position: absolute;
width: 200px;
height: 30px;
top: 0;
text-align: center;
line-height: 30px;
}
<div id="container">
<svg width="200" height="30" viewBox="-1 -2 201 33">
<path d="M0,0 h200 l-15,15 l15,15 h-200 l15,-15z" stroke="black" stroke-width="2" fill="none" />
</svg>
<div id="content">lorem ipsum</div>
</div>


您甚至可以使用二次曲线来增加一些曲线。

enter image description here

#container {
position: relative;
width: 200px;
height: 30px;
margin-bottom: 30px;
}
#content {
text-transform: uppercase;
position: absolute;
width: 200px;
height: 30px;
top: 0;
text-align: center;
line-height: 30px;
}
<div id="container">
<svg width="200" height="30" viewBox="-1 -1 201 33">
<path d="M0,0 h200 q-20,15 0,30 h-200 q20,-15 0,-30" stroke="black" stroke-linejoin="round" stroke-width="2" fill="none" />
</svg>
<div id="content">lorem ipsum</div>
</div>

<div id="container">
<svg width="200" height="30" viewBox="-1 -1 201 33">
<path d="M0,0 h200 q0,10 -15,15 q10,0 15,15 h-200 q0,-10 15,-15 q-10,0 -15,-15" stroke="black" stroke-linejoin="round" stroke-width="2" fill="none" />
</svg>
<div id="content">lorem ipsum</div>
</div>

<div id="container">
<svg width="200" height="30" viewBox="-1 -1 201 33">
<path d="M0,0 h200 q-10,0 -15,12.5 l15,2.5 l-15,2.5 q0,10 15,13 h-200 q10,0 15,-12.5 l-15,-2.5 l15,-2.5 q0,-10 -15,-12.5" stroke="black" stroke-linejoin="round" stroke-width="2" fill="none" />
</svg>
<div id="content">lorem ipsum</div>
</div>


您可以轻松添加投影效果。

enter image description here

#container {
position: relative;
width: 200px;
height: 30px;
margin-bottom: 30px;
}
#content {
text-transform: uppercase;
position: absolute;
width: 200px;
height: 30px;
top: 0;
text-align: center;
line-height: 30px;
}
<div id="container">
<svg width="205" height="35" viewBox="-1 -1 205 38">
<filter id="f">
<feGaussianBlur stdDeviation="1.5" />
</filter>
<path filter="url(#f)" d="M0,0 h200 l-15,15 l15,15 h-200 l15,-15z" stroke="black" stroke-linejoin="round" stroke-width="2" transform="translate(0,3)" fill="black" />
<path id="shape" d="M0,0 h200 l-15,15 l15,15 h-200 l15,-15z" stroke="black" stroke-linejoin="round" stroke-width="2" fill="white" />
</svg>
<div id="content">lorem ipsum</div>
</div>

<div id="container">
<svg width="205" height="35" viewBox="-1 -1 205 38">
<path filter="url(#f)" d="M0,0 h200 q0,10 -15,15 q10,0 15,15 h-200 q0,-10 15,-15 q-10,0 -15,-15" stroke="black" stroke-linejoin="round" stroke-width="2" transform="translate(0,3)" fill="black" />
<path d="M0,0 h200 q0,10 -15,15 q10,0 15,15 h-200 q0,-10 15,-15 q-10,0 -15,-15" stroke="black" stroke-linejoin="round" stroke-width="2" fill="white" />
</svg>
<div id="content">lorem ipsum</div>
</div>

<div id="container">
<svg width="205" height="35" viewBox="-1 -1 205 38">
<path filter="url(#f)" d="M0,0 h200 q-10,0 -15,12.5 l15,2.5 l-15,2.5 q0,10 15,13 h-200 q10,0 15,-12.5 l-15,-2.5 l15,-2.5 q0,-10 -15,-12.5" stroke="black" stroke-linejoin="round" stroke-width="2" transform="translate(0,3)" fill="black" />
<path d="M0,0 h200 q-10,0 -15,12.5 l15,2.5 l-15,2.5 q0,10 15,13 h-200 q10,0 15,-12.5 l-15,-2.5 l15,-2.5 q0,-10 -15,-12.5" stroke="black" stroke-linejoin="round" stroke-width="2" fill="white" />
</svg>
<div id="content">lorem ipsum</div>
</div>


或者,您始终可以使用 :after:before :伪元素。

:after:beforewidthheight :pseudo-elements 是使用一些计算出来的基本三 Angular 函数。

enter image description here

对面:after:before<的widthheight/:伪元素。左边的一个被赋予上边框和右边框,右边的一个被赋予上边框和左边框。然后,左边的旋转 45deg,右边的旋转 -45deg

div {
position: relative;
text-transform: uppercase;
width: 200px;
height: 30px;
text-align: center;
line-height: 27px;
border-top: 3px solid black;
border-bottom: 3px solid black;
box-sizing: border-box;
}
div:after,
div:before {
position: absolute;
content: '';
width: 21.21px;
height: 21.21px;
border-top: 3px solid black;
border-right: 3px solid black;
transform: rotate(45deg);
box-sizing: border-box;
top: 1px;
left: -9px;
}
div:after {
border-right: 0;
border-left: 3px solid black;
left: 100%;
margin-left: -10px;
transform: rotate(-45deg);
}
<div>lorem ipsum</div>

关于html - 倾斜或扭曲的边框形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27720098/

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