gpt4 book ai didi

html - 平滑大小变化的边框

转载 作者:太空狗 更新时间:2023-10-29 15:33:55 26 4
gpt4 key购买 nike

我正在尝试实现平滑的边框大小过渡,如下图所示:

Border

现在我怀疑纯 CSS/HTML 是否可行。我错了吗?

我会用它作为图像背景,但这个解决方案会让人头疼,因为会有很多元素具有不同的长度。

还有其他方法吗?

最佳答案

这是一个使用变换和透视的近似值(没有透明度)

.box {
width: 200px;
height: 100px;
margin: 20px;
position: relative;
border: 20px solid red;
border-width: 20px 3px 20px 20px;
border-radius:55px;
transform:perspective(112px) rotateY(5deg);
z-index: 1;
}

.box:before {
content: "";
position: absolute;
top: -5px;
left: -5px;
right: 35px;
bottom: -5px;
background: #fff;
z-index: -1;
border-radius: 40px;
transform: perspective(112px) rotateY(-7deg);
transform-origin: left;
}
<div class="box">

</div>

你可以用这两个伪元素来实现,以便能够在里面添加内容:

.box {
width: 200px;
height: 100px;
margin: 20px;
position: relative;
z-index: 0;
box-sizing: border-box;
padding: 40px;
}

.box:before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 20px solid red;
border-width: 20px 3px 20px 20px;
border-radius: 55px;
transform: perspective(112px) rotateY(5deg);
z-index: -1;
}

.box:after {
content: "";
position: absolute;
top: 10%;
left: 5%;
right: 19%;
bottom: 10%;
background: #fff;
z-index: 1;
border-radius: 36px;
transform: perspective(112px) rotateY(-7deg);
transform-origin: left;
z-index: -1;
}
<div class="box">
some text
</div>


这是另一个具有复杂背景颜色的想法,您可以在其中获得透明度并更好地控制响应:

.box {
max-width:200px;
margin:10px;
position:relative;
padding:30px 20px;
z-index:0;
box-sizing:border-box;
display:inline-block;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:2px solid red;
border-radius:40px;
background:
/* gradient position / size*/
radial-gradient(circle at bottom right,transparent 23px,red 25px) top left /34px 32px,
radial-gradient(circle at top right ,transparent 23px,red 25px) bottom left /34px 32px,
linear-gradient(red,red) left /10px 100%,
linear-gradient(to top left ,transparent 45%,red 50%) top left /85% 10px,
linear-gradient(to bottom left,transparent 45%,red 50%) bottom left /85% 10px;
background-repeat:no-repeat;
transform:perspective(100px) rotateY(5deg);
}

body {
background:pink;
}
<div class="box">
some text some text some text some text some text
</div>
<div class="box">
some text some text
</div>
<div class="box">
some text text
</div>
<div class="box">
some text
some text
some text
</div>

为了更好地理解着色,更改每个渐变的颜色:

.box {
max-width:200px;
margin:10px;
position:relative;
padding:30px 20px;
z-index:0;
box-sizing:border-box;
display:inline-block;
}
.box:before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
border:2px solid red;
border-radius:40px;
background:
radial-gradient(circle at bottom right,transparent 23px,rgba(200,0,0,0.6) 25px) top left/34px 32px,
radial-gradient(circle at top right ,transparent 23px,rgba(200,0,0,0.6) 25px) bottom left/34px 32px,
linear-gradient(yellow,yellow) left/10px 100%,
linear-gradient(to top left ,white 45%,green 50%) top left /85% 10px,
linear-gradient(to bottom left,white 45%,black 50%) bottom left/85% 10px;
background-repeat:no-repeat;
transform:perspective(100px) rotateY(5deg);
}

body {
background:pink;
}
<div class="box">
some text some text some text some text some text
</div>

关于html - 平滑大小变化的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55889836/

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