Jas*_*Lam 3 html css border linear-gradients
使用下面的代码,我只能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;
}
Run Code Online (Sandbox Code Playgroud)
电流输出:
Har*_*rry 10
您正在使用速记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;
Run Code Online (Sandbox Code Playgroud)
在上面的代码行中,100% 0 100% 0/3px 0 3px 0表示每一侧的渐变边框的大小(读作[top] [right] [bottom] [left]).原来是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;
}Run Code Online (Sandbox Code Playgroud)
<div>Some content</div>Run Code Online (Sandbox Code Playgroud)
请注意,border-image属性仍然具有相当低的浏览器支持,如果您需要支持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;
}Run Code Online (Sandbox Code Playgroud)
<div>Some content</div>Run Code Online (Sandbox Code Playgroud)