gpt4 book ai didi

html - 仅为顶部和底部边缘创建线性渐变边框?

转载 作者:搜寻专家 更新时间:2023-10-31 22:05:51 24 4
gpt4 key购买 nike

使用下面的代码,我只能为元素的底部边缘生成线性渐变 border-image。我怎样才能修改代码以使其顶部也有一个?

div {
/* gradient shining border */
border-style: solid;
border-width: 3px;
-webkit-border-image: -webkit-linear-gradient(
left,
rgba(0,0,0,1) 1%,
rgba(0,255,255,1) 50%,
rgba(0,0,0,1) 100%
) 0 0 100% 0/0 0 3px 0 stretch;
-moz-border-image: -moz-linear-gradient(
left,
rgba(0,0,0,1) 1%,
rgba(0,255,255,1) 50%,
rgba(0,0,0,1) 100%
) 0 0 100% 0/0 0 3px 0 stretch;
-o-border-image: -o-linear-gradient(
left,
rgba(0,0,0,1) 1%,
rgba(0,255,255,1) 50%,
rgba(0,0,0,1) 100%
) 0 0 100% 0/0 0 3px 0 stretch;
border-image: linear-gradient(
to left,
rgba(0,0,0,1) 1%,
rgba(0,255,255,1) 50%,
rgba(0,0,0,1) 100%
) 0 0 100% 0/0 0 3px 0 stretch;
}

当前输出:

enter image description here

最佳答案

您正在使用速记 border-image 属性来设置渐变的大小,并根据提供的值取消上、左、右边框。

100% 设置为顶部边框渐变的宽度,将 3px 设置为其高度将导致仅在顶部和底部应用渐变。

border-image: linear-gradient(to left, rgba(0, 0, 0, 1) 1%, rgba(0, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 100%) 
100% 0 100% 0/3px 0 3px 0 stretch;

上面几行代码中,100% 0 100% 0/3px 0 3px 0表示每边渐变边框的大小(读作[top] [right ] [底部] [左侧])。最初它是 0 0 100% 0/0 0 3px 0

div {
/* gradient shining border */
border-style: solid;
border-width: 3px;
border-image: linear-gradient(to left, rgba(0, 0, 0, 1) 1%, rgba(0, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 100%)
100% 0 100% 0/3px 0 3px 0 stretch;

/* other demo stuff */
height: 50px;
line-height: 50px;
background-color: #222;
color: white;
text-align: center;
}
<div>Some content</div>


请注意 border-image property still has pretty low browser support如果您需要支持 IE10 及更低版本,则无法使用。取而代之的是,您可以使用 background-image 就像下面的代码片段一样来产生类似的效果。这在 IE10 中也有效(但在 IE9 中仍然无效 - 因为它们根本不支持渐变)。

div {
/* gradient shining border */
background-image: linear-gradient(to left, rgba(0, 0, 0, 1) 1%, rgba(0, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 100%),
linear-gradient(to left, rgba(0, 0, 0, 1) 1%, rgba(0, 255, 255, 1) 50%, rgba(0, 0, 0, 1) 100%);
background-size: 100% 3px;
background-position: 0% 0%, 0% 100%;
background-repeat: no-repeat;

/* other demo stuff */
height: 50px;
line-height: 50px;
background-color: #222;
color: white;
text-align: center;
}
<div>Some content</div>

关于html - 仅为顶部和底部边缘创建线性渐变边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32329591/

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