我试图应用一个渐变的边界,我认为这是简单的这样做:
border-color: -moz-linear-gradient(top, #555555, #111111);
但这并不奏效。
有人知道做边界渐变的正确方法吗?
我试图应用一个渐变的边界,我认为这是简单的这样做:
border-color: -moz-linear-gradient(top, #555555, #111111);
但这并不奏效。
有人知道做边界渐变的正确方法吗?
当前回答
实现相同效果的另一种方法是利用多个背景图像,IE9+、较新的Firefox和大多数基于webkit的浏览器都支持这个特性:http://caniuse.com/#feat=multibackgrounds
在IE6-8中还有一些使用多个背景的选项:http://www.beyondhyper.com/css3-multiple-backgrounds-in-non-supportive-browsers/
例如,假设你想要一个5px宽的左边框,它是一个从蓝色到白色的线性渐变。创建渐变为图像,并导出为PNG格式。列出任何其他CSS背景之后的左边边界梯度:
#theBox { background: url(/images/theBox-leftBorderGradient.png) left no-repeat, ...; }
您可以通过更改背景速记属性的背景位置部分,将此技术应用于顶部、右侧和底部边界梯度。
下面是给定示例的jsFiddle: http://jsfiddle.net/jLnDt/
其他回答
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
这是一个很好的半跨浏览器的方法,有渐变边界,淡出一半。只需将颜色停止设置为rgba(0,0,0,0)
.fade-out-borders {
min-height: 200px; /* for example */
-webkit-border-image: -webkit-gradient(linear, 0 0, 0 50%, from(black), to(rgba(0, 0, 0, 0))) 1 100%;
-webkit-border-image: -webkit-linear-gradient(black, rgba(0, 0, 0, 0) 50%) 1 100%;
-moz-border-image: -moz-linear-gradient(black, rgba(0, 0, 0, 0) 50%) 1 100%;
-o-border-image: -o-linear-gradient(black, rgba(0, 0, 0, 0) 50%) 1 100%;
border-image: linear-gradient(to bottom, black, rgba(0, 0, 0, 0) 50%) 1 100%;
}
<div class="fade-out-border"></div>
用法解释:
Formal grammar: linear-gradient( [ <angle> | to <side-or-corner> ,]? <color-stop> [, <color-stop>]+ )
\---------------------------------/ \----------------------------/
Definition of the gradient line List of color stops
更多信息请点击:https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient
我同意szajmon的观点。他和昆汀回答的唯一问题是跨浏览器兼容性。
HTML:
<div class="g">
<div>bla</div>
</div>
CSS:
.g {
background-image: -webkit-linear-gradient(300deg, white, black, white); /* webkit browsers (Chrome & Safari) */
background-image: -moz-linear-gradient(300deg, white, black, white); /* Mozilla browsers (Firefox) */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffff', endColorstr='#000000', gradientType='1'); /* Internet Explorer */
background-image: -o-linear-gradient(300deg,rgb(255,255,255),rgb(0,0,0) 50%,rgb(255,255,255) 100%); /* Opera */
}
.g > div { background: #fff; }
这是一个hack,但是在某些情况下你可以通过使用background-image来指定渐变,然后用box-shadow掩盖实际的背景来达到这种效果。例如:
p {
display: inline-block;
width: 50px;
height: 50px;
/* The background is used to specify the border background */
background: -moz-linear-gradient(45deg, #f00, #ff0);
background: -webkit-linear-gradient(45deg, #f00, #ff0);
/* Background origin is the padding box by default.
Override to make the background cover the border as well. */
-moz-background-origin: border;
background-origin: border-box;
/* A transparent border determines the width */
border: 4px solid transparent;
border-radius: 8px;
box-shadow:
inset 0 0 12px #0cc, /* Inset shadow */
0 0 12px #0cc, /* Outset shadow */
inset -999px 0 0 #fff; /* The background color */
}
来自:http://blog.nateps.com/the-elusive-css-border-gradient
试试这个,在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 >