Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

css - Gradient effect for triangle shape borders

Need to add gradient effect for borders. borders are triangle shaped

enter image description here

here is 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can achieve it with SVG by using as background-image(But it might now work in all browsers because of lack of browser support).

Following SVG document will create the effect you want.

<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>

You can use it as background image as shown below.

.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;
}
<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...