Progress bar layout using CSS and HTML

2019-02-04 05:15发布

I am trying to achieve UI as shown in the image. However I am having little hard time after trying combinations of positioning now I am clueless. Can someone help me with this?

enter image description here

<style>
    .progress{
        position:relative;
        width:500px;
    }
    .bar{

    }
    .percent{

    }
</style>
<div class="progress">
    <span class="bar" width="%"></span>
    <span class="percent">50%</span>
</div>

9条回答
【Aperson】
2楼-- · 2019-02-04 05:31

To change % dynamically here is code

HTML

 <div class="progress">
          <span class="percent">{{currentTimer}}</span>
          <div class="bar" [style.width]="progress + '%'"></div>
          <span class="duration">{{duration}}</span>
      </div>

CSS

.progress {
    width: 100%;   
  //  border: 1px solid black;
    position: relative;
    padding: 0px;
   }

   .percent {
    position: absolute;   
    left: 0%;
   }

   .bar {
    height: 16px;
    background-color: rgb(41, 49, 32);

   }
   .duration {
    position: absolute;   
    left: 90%;
    top:-5%
   }
查看更多
Anthone
3楼-- · 2019-02-04 05:37
<style>
.progress{
    position:relative;
    width:500px;
    height:30px;
    border:1px solid #000;
}
.bar{
  //Change width with javascript
  position:absolute;
  top:0px; left:0px;
  background:#0F3;
  max-width:500px;
  height:30px;
}
.percent{
   position:relative;
   width:100%;
   text-align:center;
   font-size:18px;
   padding:10px;
}
</style>
<div class="progress">
<div class="percent"><span>50%</span><div class="bar"></div></div>
</div>

You'll have to play around with the font-size and padding to get it just right, but that should about do it.

查看更多
Anthone
4楼-- · 2019-02-04 05:42

HTML:

<div id="progress">
    <span id="percent">30%</span>
    <div id="bar"></div>
</div>

CSS:

#progress {
 width: 500px;   
 border: 1px solid black;
 position: relative;
 padding: 3px;
}

#percent {
 position: absolute;   
 left: 50%;
}

#bar {
 height: 20px;
 background-color: green;
 width: 30%;
}

Sample here: http://jsfiddle.net/WawPr/

查看更多
倾城 Initia
5楼-- · 2019-02-04 05:47

Just change the onclick function as follows and you will have an animated version of the accepted solution

$('.changeprogress').click(function() {
  var width = 1;
  var percent = $(this).text().replace('%','') ;
  var id = setInterval(frame, 25);

  function frame() {
    if (width >= percent) {
      clearInterval(id);
    } else {
      width++;
      $('.bar').css('width', width + '%');
      $('.percent').text(width + '%');
    }
  }

});

http://jsfiddle.net/Zfzva/418/ can see it here.

thanks to

https://stackoverflow.com/a/5865894/2815227

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_progressbar_3

查看更多
再贱就再见
6楼-- · 2019-02-04 05:47

Take this example....

HTML CODE:

<div id="progressbar" style="height:25px;">
    <span class="text"></span>
</div>

CSS

.text { 
    color: black;
    margin-left: 130px;
    position: absolute;
}

JQUERY:

$( "#progressbar" ).progressbar({ 
   value: some_Value;
 });
$("#progressbar span.text").text(some_Value + "%");
查看更多
Root(大扎)
7楼-- · 2019-02-04 05:49

I did half the work for you.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
  <style type="text/css">
 #container { width:350px; }
 #main_bar {
    width:374px;
    height:35px;
    border:1px solid #111;
 }
 #inner_bar {
    float;left;
    width:150px; 
    background:#00ff00;
    margin:-20px 0 0 5px;
}
p {
    margin-top:-33px;
    text-align:center; }

</style>

    <title>The document title</title>
  </head>
  <body>
    <div id="container">
    <div id="main_bar">
    </div><!--#main_bar-->
    <div id="inner_bar">
    <p>hello</p>
    </div><!--#inner_bar-->
    <p>30%</p>
</div>
  </body>
</html>

You can mess with the widths, margins, paddings! I got lazy, and didn't want to finish it. lol

查看更多
登录 后发表回答