使渐变边框看起来像一条线

时间:2016-05-03 21:33:51

标签: css gradient linear-gradients

如何使颜色之间的渐变边框看起来像一条线?是否还有一种方法可以在左下角而不是按钮右侧中间开始线?我正在使用这个css:

background: linear-gradient(to right bottom, #00C9FF 30%, black 50%)

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以使用以下代码获得预期结果:



div {
  background: linear-gradient(to right bottom, #00C9FF calc(50% - 1px), black calc(50% + 1px));
  border:7px solid #00C9FF;
  color:#fff;
  height:100px;
  line-height:100px;
  text-align:center;
  width:100px;
}

<div>Test</div>
&#13;
&#13;
&#13;

需要calc()才能使线条平滑。否则边框在某些浏览器上看起来很奇怪。

答案 1 :(得分:0)

您应该将两种颜色移动到相同的位置:

background: linear-gradient(to right bottom, #00C9FF 30%, black 30%);
相关问题