html - 在CSS中给垂直线设置渐变

标签 html css

我在 html 中使用了一条垂直线,我想为其提供渐变。我已经尝试了一切,但没有一个对我有用。这是我的代码:

.vline
    {
      border-left: 5px solid green;   /* this green color gets displayed and not the gradient */
      
      background: #67B26F;  /* fallback for old browsers */
      background: -webkit-linear-gradient(to left, #4ca2cd, #67B26F);  /* Chrome 10-25, Safari 5.1-6 */
      background: linear-gradient(to left, #4ca2cd, #67B26F); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 
                                                                26+, Opera 12+, Safari 7+ */
      height: 50px;
    }
<div class="vline"></div>

编辑:显示我在左边框中定义的绿色。梯度不是。它应该覆盖以前的颜色。

最佳答案

您能检查一下下面的代码吗?希望它对你有用。我们根据您的要求使用伪元素来制作渐变边框。

请引用此链接:https://jsfiddle.net/yudizsolutions/9noqwj0c/1/

.vline {
  position: relative;
  background: #67B26F;
  /* fallback for old browsers */
  background: -webkit-linear-gradient(to left, #4ca2cd, #67B26F);
  /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(to left, #4ca2cd, #67B26F);
  /* W3C, IE 10+/ Edge, Firefox 16+, Chrome                                                         26+, Opera 12+, Safari 7+ */
  height: 50px;
  padding-left: 10px;
}


.vline:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 5px;
  height: 100%;
  background: rgb(219, 85, 83);
  background: -webkit-linear-gradient(top, rgba(219, 85, 83, 1) 0%, rgba(183, 183, 25, 1) 100%);
  background: linear-gradient(to bottom, rgba(219, 85, 83, 1) 0%, rgba(183, 183, 25, 1) 100%);

}
<div class="vline"></div>

关于html - 在CSS中给垂直线设置渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66541235/

相关文章:

javascript - 由于一些神奇的隐藏数字,CSS 类将无法工作

javascript - 如何将validation_errors()放在文本字段的右侧?

javascript - Java 小程序未显示在 Web 浏览器上

javascript - 无法在 material-ui Button 组件中读取 null 的属性(读取 'pulsate')

javascript - 当取决于屏幕分辨率时,如何计算每行显示的 div 数量

html - 将 <p> 与图像对齐不起作用

html - css 让元素宽度自动增长而父宽度自动增长

javascript - 为什么 IE11 对减号的 Node.normalize() 处理不正确?

html - div 如何在 css 中填充父元素

html - CSS:将高度对齐的按钮附加到输入