使进度条响应

时间:2018-05-29 08:13:55

标签: javascript html css

我有这些progress bars,它们可以作为评级使用,看起来很棒: enter image description here

我已应用了一些CSS,并通过从文本文件中读取值来更改JavaScript的宽度。 但是根本没有响应,只要窗口调整大小: enter image description here

HTML

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="second-part">

              <div class="row">
                    <div class="side">
                      <div>5 stars</div>
                    </div>
                    <div class="middle">
                      <div class="bar-container">
                        <div class="bar11" style="width: 10% ; height: 18px; background-color: gold;"></div>
                      </div>
                    </div>
                    <div class="side right">
                      <div class="p11">150</div>
                    </div>
                    <div class="side">
                      <div>4 stars</div>
                    </div>
                    <div class="middle">
                      <div class="bar-container">
                        <div class="bar12" style="width: 10% ; height: 18px; background-color: gold;"></div>
                      </div>
                    </div>
                    <div class="side right">
                      <div class="p12">63</div>
                    </div>
                    <div class="side">
                      <div>3 stars</div>
                    </div>
                    <div class="middle">
                      <div class="bar-container">
                        <div class="bar13" style="width: 10% ; height: 18px; background-color: gold;"></div>
                      </div>
                    </div>
                    <div class="side right">
                      <div class="p13">15</div>
                    </div>
                    <div class="side">
                      <div>2 stars</div>
                    </div>
                    <div class="middle">
                      <div class="bar-container">
                        <div class="bar14" style="width: 10% ; height: 18px; background-color: gold;"></div>
                      </div>
                    </div>
                    <div class="side right">
                      <div class="p14">6</div>
                    </div>
                    <div class="side">
                      <div>1 star</div>
                    </div>
                    <div class="middle">
                      <div class="bar-container">
                        <div class="bar15" style="width: 10% ; height: 18px; background-color: gold;"></div>
                      </div>
                    </div>
                    <div class="side right">
                      <div class="p15">20</div>
                    </div>
                  </div>
                </div>

CSS

* {
    box-sizing: border-box;
}

/* Three column layout */
.side {

        float: left;
        width: 15%;
        margin-top:10px;
    }

    .middle {
        margin-top:10px;
        float: left;
        width: 70%;
    }

    /* Place text to the right */
    .right {
        text-align: left;

    }


    /* Clear floats after the columns */
    .row:after {
        content: "";
        display: table;
        clear: both;
    }


    /* The bar container */
    .bar-container {
        width: 90%;
        background-color: #f1f1f1;
        text-align: center;
        color: white;
    }
    /* Responsive layout - make the columns stack on top of each other instead of next to each other */
    @media (max-width: 400px) {
        .side, .middle {
            width: 100%;
        }
        .right {
            display: none;
        }
    }

JavaScript更改进度条宽度:

var par1 = 4;
  for(var i = 10; i < 16; i++) {
    $('.p' + (i+1)).text(table[0][par1]);
    $('.bar' + (i+1)).css("width", table[0][par1]);
    par1++;
  }

我怎样才能让它更具响应性?提前谢谢!

1 个答案:

答案 0 :(得分:0)

我建议使用css flexbox,因此在调整页面大小时,项目会换行而不是重叠。您可以使用媒体查询来调整项目和容器的大小,以便它们不会重叠/换行。这个网站对flexbox有一个很好的解释:A Complete Guide to Flexbox