如何向边框添加渐变

Thi*_*kSo 5 html css css3

我想知道是否可以将渐变添加到边框顶部而不影响边框右边界或边框左边,在这种情况下是透明的.我尝试添加渐变颜色但它会影响边框左边框和右边框我试图让边框左边框和边框右边透明

#borderone {
        border-top: 33px solid #354658;
        border-left: 33px solid transparent;
        border-right: 33px solid transparent;
        margin: 0 auto;
        min-width: 1277px;
    }
    <div id='borderone'></div>
Run Code Online (Sandbox Code Playgroud)

你可以看到这是我想要它做的虽然我想要一个渐变背景颜色而不是这个坚实的深蓝色http://jsfiddle.net/EHELN/

val*_*als 1

您可以使用渐变背景来获得此效果,并使用左侧和右侧的 2 个伪元素来获得倾斜的角

 .test {
    border-left: 33px solid transparent;
    border-right: 33px solid transparent;
    height: 33px;
    background: linear-gradient(90deg, black, blue);
    margin: 0 auto;
    min-width: 42px;
    background-clip: content-box;
    position: relative;
}

.test:before, .test:after {
    content: '';
    position: absolute;
    width: 33px;
    height: 100%;
}

.test:before {
    background: linear-gradient(45deg, transparent 50%, black 50%);
    right: 100%;
}

.test:after {
    background: linear-gradient(315deg, transparent 50%, blue 50%);
    left: 100%;
}
Run Code Online (Sandbox Code Playgroud)

演示

看来我误解了方向。尝试以另一种方式实现(对于 webkit)

 .test {
    border-left: 33px solid transparent;
    border-right: 33px solid transparent;
    height: 33px;
    background: linear-gradient(0deg, black, red);
    margin: 0 auto;
    min-width: 42px;
    background-clip: content-box;
    position: relative;
}

.test:before, .test:after {
    content: '';
    position: absolute;
    width: 45px;
    height: 45px;
    bottom: 0px;
}

.test:before {
    -webkit-transform: rotate(45deg);
    -webkit-transform-origin: bottom right;
    background: linear-gradient(-45deg, black 0, red 32px, transparent 32px);
    right: 100%;
}

.test:after {
    -webkit-transform: rotate(-45deg);
    -webkit-transform-origin: bottom left;
    background: linear-gradient(45deg, black 0, red 32px, transparent 32px);
    left: 100%;
}
Run Code Online (Sandbox Code Playgroud)

演示2