HTML5/CSS3實現五彩進度條應用

今天要介紹的是一款基於HTML5和CSS3的進度條應用,這款進度條是靜態的,僅提供進度條的五彩外觀。固然你能夠在CSS中動態設置進度值來讓其變得動態,一個很好的實現方式是利用jQuery動態改變CSS中的進度值,讓進度條實時動起來。具體效果你們能夠看演示。css

css3-progress-5-colors

你也能夠在這裏查看在線演示html

接下來咱們來分析一下這款進度條的源代碼以及實現思路,代碼主要由HTML和CSS組成,若是你須要動態改變進度值,也能夠本身添加Javascript代碼,也是比較簡單的。html5

HTML代碼:

<section class="container">
    <div class="progress">
      <span style="width: 20%;"><span>20%</span></span>
    </div>

    <div class="progress">
      <span class="green" style="width: 40%;"><span>40%</span></span>
    </div>

    <div class="progress">
      <span class="orange" style="width: 60%;"><span>60%</span></span>
    </div>

    <div class="progress">
      <span class="red" style="width: 80%;"><span>80%</span></span>
    </div>

    <div class="progress">
      <span class="blue" style="width: 100%;"><span>100%</span></span>
    </div>
  </section>

從HTML結構中咱們能夠看出,類名爲progress的div是整個進度條的父容器,裏面的span則是當前進度,經過width來定義不一樣的進度值,同時定義不一樣的顏色類,好比orange,以便待會在CSS中進行樣式渲染。css3

CSS代碼:

.progress {
  height: 20px;
  background: #ebebeb;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
  border-radius: 10px;
}
.progress > span {
  position: relative;
  float: left;
  margin: 0 -1px;
  min-width: 30px;
  height: 18px;
  line-height: 16px;
  text-align: right;
  background: #cccccc;
  border: 1px solid;
  border-color: #bfbfbf #b3b3b3 #9e9e9e;
  border-radius: 10px;
  background-image: -webkit-linear-gradient(top, #f0f0f0 0%, #dbdbdb 70%, #cccccc 100%);
  background-image: -moz-linear-gradient(top, #f0f0f0 0%, #dbdbdb 70%, #cccccc 100%);
  background-image: -o-linear-gradient(top, #f0f0f0 0%, #dbdbdb 70%, #cccccc 100%);
  background-image: linear-gradient(to bottom, #f0f0f0 0%, #dbdbdb 70%, #cccccc 100%);
  -webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
}
.progress > span > span {
  padding: 0 8px;
  font-size: 11px;
  font-weight: bold;
  color: #404040;
  color: rgba(0, 0, 0, 0.7);
  text-shadow: 0 1px rgba(255, 255, 255, 0.4);
}
.progress > span:before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1;
  height: 18px;
  background: url("../img/progress.png") 0 0 repeat-x;
  border-radius: 10px;
}
.progress .green {
  background: #85c440;
  border-color: #78b337 #6ba031 #568128;
  background-image: -webkit-linear-gradient(top, #b7dc8e 0%, #99ce5f 70%, #85c440 100%);
  background-image: -moz-linear-gradient(top, #b7dc8e 0%, #99ce5f 70%, #85c440 100%);
  background-image: -o-linear-gradient(top, #b7dc8e 0%, #99ce5f 70%, #85c440 100%);
  background-image: linear-gradient(to bottom, #b7dc8e 0%, #99ce5f 70%, #85c440 100%);
}
.progress .red {
  background: #db3a27;
  border-color: #c73321 #b12d1e #8e2418;
  background-image: -webkit-linear-gradient(top, #ea8a7e 0%, #e15a4a 70%, #db3a27 100%);
  background-image: -moz-linear-gradient(top, #ea8a7e 0%, #e15a4a 70%, #db3a27 100%);
  background-image: -o-linear-gradient(top, #ea8a7e 0%, #e15a4a 70%, #db3a27 100%);
  background-image: linear-gradient(to bottom, #ea8a7e 0%, #e15a4a 70%, #db3a27 100%);
}
.progress .orange {
  background: #f2b63c;
  border-color: #f0ad24 #eba310 #c5880d;
  background-image: -webkit-linear-gradient(top, #f8da9c 0%, #f5c462 70%, #f2b63c 100%);
  background-image: -moz-linear-gradient(top, #f8da9c 0%, #f5c462 70%, #f2b63c 100%);
  background-image: -o-linear-gradient(top, #f8da9c 0%, #f5c462 70%, #f2b63c 100%);
  background-image: linear-gradient(to bottom, #f8da9c 0%, #f5c462 70%, #f2b63c 100%);
}
.progress .blue {
  background: #5aaadb;
  border-color: #459fd6 #3094d2 #277db2;
  background-image: -webkit-linear-gradient(top, #aed5ed 0%, #7bbbe2 70%, #5aaadb 100%);
  background-image: -moz-linear-gradient(top, #aed5ed 0%, #7bbbe2 70%, #5aaadb 100%);
  background-image: -o-linear-gradient(top, #aed5ed 0%, #7bbbe2 70%, #5aaadb 100%);
  background-image: linear-gradient(to bottom, #aed5ed 0%, #7bbbe2 70%, #5aaadb 100%);
}

這裏咱們對前面HTML中定義的不一樣顏色的進度條進行了CSS定義,設置背景顏色、邊框顏色以及利用linear-gradient屬性設置線性漸變的背景。看起來CSS代碼很是簡單,也沒有太多CSS3的東西。以上只是核心代碼,你也能夠本身下載完整的代碼研究。源碼下載>>web

相關文章
相關標籤/搜索