代码之家  ›  专栏  ›  技术社区  ›  ar2015

向水平条形图添加标签

  •  2
  • ar2015  · 技术社区  · 6 年前

    我是新来的HTML。在下表中,如何添加一些标签,例如

    Team 1up
    Team blue
    Team tigers
    Team watermelon
    Team crazyred
    Team Melt
    

    $(function() {
          $('.progress-fill span').each(function(){
            var percent = $(this).html();
            $(this).parent().css('width', percent);
          });
    });
    body {
      background: #999;
    }
    
    .container {
      width: 500px;
      margin: 20px;
      background: #fff;
      padding: 20px;
      overflow: hidden;
      float: left;
    }
    
    .horizontal .progress-bar {
      float: left;
      height: 18px;
      width: 100%;
      padding: 3px 0;
    }
    
    .horizontal .progress-track {
      position: relative;
      width: 100%;
      height: 20px;
      background: #ebebeb;
    }
    
    .horizontal .progress-fill {
      position: relative;
      background: #666;
      height: 20px;
      width: 50%;
      color: #fff;
      text-align: center;
      font-family: "Lato","Verdana",sans-serif;
      font-size: 12px;
      line-height: 20px;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="container horizontal flat">
      <h2>Team performances</h2>
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>100%</span>
          </div>
        </div>
      </div>
    
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>75%</span>
          </div>
        </div>
      </div>
    
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>60%</span>
          </div>
        </div>
      </div>
    
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>20%</span>
          </div>
        </div>
      </div>
    
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>34%</span>
          </div>
        </div>
      </div>
    
      <div class="progress-bar horizontal">
        <div class="progress-track">
          <div class="progress-fill">
            <span>82%</span>
          </div>
        </div>
      </div>
    </div>
    2 回复  |  直到 6 年前
        1
  •  2
  •   Iman Mohamadi    6 年前

    progress-group progress-label progress-bar 进度小组 照顾孩子的责任。我用的是flex,在这种情况下是合理的。如果您想在将来添加额外的组件,这将为您提供更多的控制。

    https://codepen.io/anon/pen/oPVyYm

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="container horizontal flat">
      <h2>Team performances</h2>
      <div class="progress-group">
        <div class="progress-label">Team 1up</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>100%</span>
            </div>
          </div>
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-label">Team blue</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>75%</span>
            </div>
          </div>
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-label">Team tigers</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>60%</span>
            </div>
          </div>
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-label">Team watermelon</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>20%</span>
            </div>
          </div>
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-label">Team crazyred</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>34%</span>
            </div>
          </div>
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-label">Team Melt</div>
        <div class="progress-bar horizontal">
          <div class="progress-track">
            <div class="progress-fill">
              <span>82%</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    
    
    
    body {
      background: #999;
    }
    
    .container {
      width: 500px;
      margin: 20px;
      background: #fff;
      padding: 20px;
      overflow: hidden;
      float: left;
    }
    
    .horizontal .progress-bar {
      float: left;
      height: 18px;
      width: 100%;
      padding: 3px 0;
    }
    
    .horizontal .progress-track {
      position: relative;
      width: 100%;
      height: 20px;
      background: #ebebeb;
    }
    
    .horizontal .progress-fill {
      position: relative;
      background: #666;
      height: 20px;
      width: 50%;
      color: #fff;
      text-align: center;
      font-family: "Lato","Verdana",sans-serif;
      font-size: 12px;
      line-height: 20px;
    }
    
    .progress-group {
      display: flex;
    }
    
    .progress-label {
      width: 170px;
      text-align: right;
      padding-right: 10px;
    }
    
    .progress-label::after {
      content: ":";
    }
    
    
    
    $(function() {
          $('.progress-fill span').each(function(){
            var percent = $(this).html();
            $(this).parent().css('width', percent);
          });
    });
    
        2
  •  1
  •   JABedford    6 年前

    https://codepen.io/JABedford/pen/RYdMjV

    <div class="progress-bar horizontal">
    <span class="name">Team Name</span>
    <div class="progress-track">
      <div class="progress-fill">
        <span>75%</span>
      </div>
    </div>
    

        body {
          background: #999;
        }
    
        .container {
          width: 500px;
          margin: 20px;
          background: #fff;
          padding: 20px;
          overflow: hidden;
          float: left;
        }
    
        .horizontal .progress-bar {
          float: right;
          height: 18px;
          width: 100%;
          padding: 3px 0;
        }
    
        .horizontal .progress-track {
          position: relative;
          float: left;
          width: 80%;
          height: 20px;
          background: #ebebeb;
        }
    
        .horizontal .progress-fill {
          position: relative;
          background: #666;
          height: 20px;
          width: 50%;
          color: #fff;
          text-align: center;
          font-family: "Lato","Verdana",sans-serif;
          font-size: 12px;
          line-height: 20px;
        }