【问题标题】:CSS Bottom Right Border Gradient to TransparentCSS右下边框渐变为透明
【发布时间】:2014-12-23 10:53:12
【问题描述】:

标题说明了一切,

我需要设置一个从下到上透明但仅在右侧的黑色边框。

这段代码部分完全符合我的需要,但我不知道如何让它在左侧消失,所以只有右侧有边框..

.bottom-to-top {
border-width: 3px;
border-style: solid;
-webkit-border-image: 
  -webkit-gradient(linear, 0 100%, 0 0, from(black), to(rgba(0, 0, 0, 0))) 1 100%;
-webkit-border-image: 
  -webkit-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;
-moz-border-image:
  -moz-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;  
-o-border-image:
  -o-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;
border-image:
  linear-gradient(to top, black, rgba(0, 0, 0, 0)) 1 100%;}

【问题讨论】:

  • 下方设置边框左:3px纯黑色
  • 我的代码有我想要的边框,但在两边..我希望左边框消失..只有右边是可见的,所以右边从下到上透明

标签: html css border gradient


【解决方案1】:

只需将 border-width: 3px; 更改为 border-width: 0 3px 0 0; 您正在设置所有边的边框

.bottom-to-top {
  width: 200px;
  height: 100px;
  border-width: 0 3px 0 0;
  border-style: solid;
  -webkit-border-image: -webkit-gradient(linear, 0 100%, 0 0, from(black), to(rgba(0, 0, 0, 0))) 1 100%;
  -webkit-border-image: -webkit-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;
  -moz-border-image: -moz-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;
  -o-border-image: -o-linear-gradient(bottom, black, rgba(0, 0, 0, 0)) 1 100%;
  border-image: linear-gradient(to top, black, rgba(0, 0, 0, 0)) 1 100%;
}
<div class="bottom-to-top"></div>

【讨论】:

    【解决方案2】:

    您可以使用 :after :pseudo-element 来执行此操作。

    .bottom-to-top {
      position: relative;
      width: 200px;
      height: 50px;
    }
    .bottom-to-top:after {
      position: absolute;
      right: 0;
      content: '';
      height: 100%;
      width: 3px;
      background: linear-gradient(to top, black, transparent);
    }
    <div class="bottom-to-top"></div>

    【讨论】:

    • 发布的代码 SW4,似乎完全按照我的意愿工作。只是它不能在 IE 上工作,但可以在 Chorome/Firefox @chipChoko 上正常工作,我不需要四面八方的黑色边框..只是右侧的透明的..
    • @Rifshan:这可能是因为 IE 仅从 v11 开始支持 border-image 属性。
    • 芯片,你的代码在 IE 中运行良好,你能不能让边框出现在右边,其余的没有边框......对不起,如果我唠叨太多,但这真的是对我来说很复杂:/
    • @Rifshan:然后在 .border-to-top 类中将border black 颜色选择更改为transparent