我试图应用一个渐变的边界,我认为这是简单的这样做:
border-color: -moz-linear-gradient(top, #555555, #111111);
但这并不奏效。
有人知道做边界渐变的正确方法吗?
我试图应用一个渐变的边界,我认为这是简单的这样做:
border-color: -moz-linear-gradient(top, #555555, #111111);
但这并不奏效。
有人知道做边界渐变的正确方法吗?
当前回答
Mozilla目前只支持CSS渐变作为background-image属性的值,以及在简写背景中。
——https://developer.mozilla.org/en/CSS/-moz-linear-gradient
Example 3 - Gradient Borders
border: 8px solid #000;
-moz-border-bottom-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-top-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-left-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
-moz-border-right-colors: #555 #666 #777 #888 #999 #aaa #bbb #ccc;
padding: 5px 5px 5px 15px;
——http://www.cssportal.com/css3-preview/borders.htm
其他回答
而不是边框,我会使用背景渐变和填充。同样的外观,但更简单,更有支撑。
举个简单的例子:
.g { Background-image: -webkit-gradient(线性,左下,左上,彩色停止(0.33,rgb(14,173,173)),彩色停止(0.67,rgb(0,255,255))); 背景-图像:-moz-linear-gradient(中底,rgb(14,173,173) 33%, rgb(0,255,255) 67%); 填充:2 px; } .g > div{背景:#fff;} < div class = " g " > < div > bla < / div > < / div >
编辑:你也可以利用:before选择器@WalterSchwarz指出:
body { padding: 20px; } .circle { width: 100%; height: 200px; background: linear-gradient(to top, #3acfd5 0%, #3a4ed5 100%); border-radius: 100%; position: relative; text-align: center; padding: 20px; box-sizing: border-box; } .circle::before { border-radius: 100%; content: ''; background-image: linear-gradient(to bottom, #3acfd5 0%, #3a4ed5 100%); top: -10px; left: -10px; bottom: -10px; right: -10px; position: absolute; z-index:-1; } <div class="circle"></div>
border-image-slice将扩展CSS的border-image渐变
这(正如我所理解的)阻止了默认的“图像”切片-没有它,如果边界只在一侧,什么都不会出现,如果它围绕整个元素,每个角落会出现四个微小的梯度。
身体{ 边框:16px实体透明; 边界图像:线性渐变(45度,红,黄); border-image-slice: 1; 身高:120 px; border - radius: 10 px;/*将没有影响*/ }
这是一个带有透明背景的渐变边界,使用边界半径
.gradient-border {
border-radius: 999px;
padding: 10px 3rem;
display: inline-block;
position: relative;
background: transparent;
border: none;
}
.gradient-border::before {
content: "";
position: absolute;
inset: 0;
padding: 2px;
border-radius: 9999px;
background: linear-gradient(87.36deg, blue 6.42%, red 84.24%),
linear-gradient(0deg, #FFFFFF, #FFFFFF);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
现场演示:https://jsfiddle.net/jbernier/0eypxc74/1/
这里有一篇很好的css技巧文章:https://css-tricks.com/gradient-borders-in-css/
我能够想出一个非常简单的,单元素的解决方案,使用多个背景和background-origin属性。
.wrapper {
background: linear-gradient(#222, #222),
linear-gradient(to right, red, purple);
background-origin: padding-box, border-box;
background-repeat: no-repeat; /* this is important */
border: 5px solid transparent;
}
这种方法的优点是:
它不受z指数的影响 它可以通过改变透明边框的宽度来轻松缩放
去https://codepen.io/AlexOverbeck/pen/axGQyv?editors=1100看看吧
试试这个,在web-kit上工作很好
.border { 宽度:400 px; 填充:20 px; border-top: 10px solid #FFFF00; border-bottom:10px solid #FF0000; 背景图片: 线性渐变(# FFFF00 # FF0000), 线性渐变(# FFFF00 # FF0000) ; background-size: 10 px 100%; 背景位置:0 0,100% 0; 平铺方式:不再重演; } < div class = "边境”>你好!< / div >