三角形边框的渐变效果

时间:2016-09-23 04:16:36

标签: css css3 border gradient css-shapes

需要为边框添加渐变效果。边框是三角形的

enter image description here

此处为the jsfiddle code



.progress-indicator-wrapper {
  margin: 0 10px;
  font-size: 16px;
  color: #2f2f2f;
  background-image: linear-gradient(to bottom, #e7e7e7, #d8d8d8);
}
.progress-indicator {
  display: table;
  width: 100%;
  text-align: center;
  line-height: 20px;
}
.progress-indicator > div {
  display: table-cell;
  margin-top: 0;
  padding: 20px;
  position: relative;
}
.progress-indicator > div.progress-active::before {
  content: " ";
  position: absolute;
  left: 0;
  top: 0;
  border-top: 30px solid transparent;
  border-bottom: 30px solid transparent;
  border-left: 20px solid #e7e7e7;
}
.progress-indicator > div.progress-active::after {
  content: " ";
  position: absolute;
  right: -20px;
  top: 0;
  border-top: 30px solid transparent;
  border-bottom: 30px solid transparent;
  border-left: 20px solid #2980b9;
}
.progress-active {
  color: #fff;
  background-image: linear-gradient(to bottom, #3498db, #2980b9);
}

<div class="progress-indicator-wrapper">
  <div class="progress-indicator">
    <div>
      <span class="progress-txt">Step 1 </span>
    </div>
    <div class="progress-active">
      <span class="progress-txt">Step 2</span>
    </div>
    <div>
      <span class="progress-txt">Step 3</span>
    </div>
    <div>
      <span class="progress-txt">Step 4</span>
    </div>
    <div>
      <span class="progress-txt">Step 5</span>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

我面临着为“边界左边”添加渐变的问题。而不是平坦的颜色。并且需要保持三角形状。

只使用CSS吗?

3 个答案:

答案 0 :(得分:2)

您可以使用SVG background-image来实现它(但由于缺乏浏览器支持,它现在可能适用于所有浏览器)。

关注SVG文档会创建您想要的效果。

<svg version='1.1' xmlns='http://www.w3.org/2000/svg' width='132' height='60' viewBox='0 0 132 60'>
    <defs>
        <linearGradient id='Gradient1'>
            <stop stop-color='%233498db' offset='0%'/>
            <stop stop-color='%232980b9' offset='100%'/>
        </linearGradient>
    </defs>
    <polygon points='0,0 112,0 132,30 112,60 0,60 15,30' fill='url(%23Gradient1)'></polygon>
</svg>

您可以将其用作背景图像,如下所示。

&#13;
&#13;
.progress-indicator-wrapper {
  margin: 0 10px;
  font-size: 16px;
  color: #2f2f2f;
  background-image: linear-gradient(to bottom, #e7e7e7, #d8d8d8);
}
.progress-indicator {
    display: table;
    width: 100%;
    text-align: center;
    line-height: 20px;
}
.progress-indicator > div {
    display: table-cell;
    margin-top: 0;
    padding: 13px 20px;
    position: relative;
}
.progress-active {
  background: url("data:image/svg+xml;utf8,<svg version='1.1' xmlns='http://www.w3.org/2000/svg' width='132' height='60' viewBox='0 0 132 60'><defs>  <linearGradient id='Gradient1'><stop stop-color='%233498db' offset='0%'/><stop stop-color='%232980b9' offset='100%'/></linearGradient></defs><polygon points='0,0 112,0 132,30 112,60 0,60 15,30' fill='url(%23Gradient1)'></polygon></svg>")  no-repeat;
  background-size: 100% 100%;
  color: #fff;
}
&#13;
<div class="progress-indicator-wrapper">
  <div class="progress-indicator">
    <div>
      <span class="progress-txt">Step 1 </span>
    </div>
    <div class="progress-active">
      <span class="progress-txt">Step 2</span>
    </div>
    <div>
      <span class="progress-txt">Step 3</span>
    </div>
    <div>
      <span class="progress-txt">Step 4</span>
    </div>
    <div>
      <span class="progress-txt">Step 5</span>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

尝试检查此链接。 似乎bellow link就是你要找的东西

http://dabblet.com/gist/3725803

这里的代码可以参考

的style.css

.rectangle {
    float: left;
    position: relative;
    height: 80px;
    width: 240px;
    border: solid 1px #ccc;
    border-right: none;
    background: #eee linear-gradient(white, #f1f1f1 37%, #e1e1e1 57%, #f6f6f6);
    cursor: pointer;
}
.rectangle:after {
    position: absolute;
    top: 16px; right: -25px;
    width: 48px;
    height: 47px;
    border-left: solid 1px #ccc;
    border-top: solid 1px #ccc;
    transform: rotate(134deg) skewX(-10deg) skewY(-10deg);
    background: #eee linear-gradient(45deg, white, #f1f1f1 37%, #e1e1e1 57%, #f6f6f6);
    content: '';
}

HTML

<div class='rectangle'></div>

答案 2 :(得分:0)

我已经完成了绘制形状并避开边框。最好使用渐变。

解决方案:here is jsfiddle code

Target .NET Platform Standard
.progress-indicator-wrapper {
  margin: 0 10px;
  font-size: 16px;
  color: #2f2f2f;
   background-image: linear-gradient(to bottom, #e7e7e7, #d8d8d8);
}

.progress-indicator {
    display: table;
    width: 100%;
    text-align: center;
    line-height: 20px;
}

.progress-indicator > div {
    display: table-cell;
    margin-top: 0;
    padding: 10px;
    position: relative;
}

.progress-indicator > .progress-active {
  padding: 20px 20px 20px 30px;
  color: #fff;
   background-image: linear-gradient(to bottom, #3498db, #2980b9);
}
.progress-indicator > .progress-active + div {
  padding-left: 20px;
}
/* Triangle arrow define  */
.progress-active::before, .progress-active::after {
  content: "";
  width: 34px;
  padding-bottom: 30px;
  position: absolute;
  overflow: hidden;
  transform: rotate(90deg);
  z-index: 2;  

  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;

  background-image: linear-gradient(45deg, #e7e7e7, #d8d8d8);

  -webkit-transform-origin: 0 100%;
  -ms-transform-origin: 0 100%;
  transform-origin: 0 100%;
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);

  transform: rotate(120deg) skewX(-30deg);
}

.progress-active::before {
  top: -30px;
  left: 0px;
}

.progress-active::after {
  top: -30px;
  right: -34px;
   background-image: linear-gradient(45deg, #3498db, #2980b9);
}