Bootstrap 4评分进度条

huangapple go评论79阅读模式
英文:

Bootstrap 4 Rating with progress bar

问题

使用Bootstrap 4,我想要实现这个效果:

Bootstrap 4评分进度条

忽略“查看全部”和“4,327 条评分”

到目前为止,我只得到了这个:

Bootstrap 4评分进度条

无论是5、4、3...的评分,我都可以轻松地用字体图标替代它们。

这是我的代码:

<h4>评分和评论</h4>
<div class="d-flex">
  <div class="text-center">
    <span class="display-4 font-weight-bolder">3.1</span><br>
    <span class="text-black-50">5分满分</span>
  </div>
  <div class="flex-grow-1">
    <div class="row">
      <div class="col-4 text-right">
        5
      </div>
      <div class="col-8">
        <div class="progress" style="height: 2px;">
          <div class="progress-bar" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4 text-right">
        4
      </div>
      <div class="col-8">
        <div class="progress" style="height: 2px;">
          <div class="progress-bar" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4 text-right">
        3
      </div>
      <div class="col-8">
        <div class="progress" style="height: 2px;">
          <div class="progress-bar" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4 text-right">
        2
      </div>
      <div class="col-8">
        <div class="progress" style="height: 2px;">
          <div class="progress-bar" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4 text-right">
        1
      </div>
      <div class="col-8">
        <div class="progress" style="height: 2px;">
          <div class="progress-bar" role="progressbar" style="width: 75%;" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
        </div>
      </div>
    </div>
  </div>
</div>

我如何实现以下效果:

  • 使进度条在垂直方向上与文本/星号垂直居中对齐。
  • 注意我正在使用Row/Col,但我更喜欢使用flexbox。
  • 使用尽可能少的CSS。
英文:

Using Bootstrap 4. I want to achieve this:

Bootstrap 4评分进度条

Ignore "See All" and "4,327 Ratings"

I ended up only getting this so far:

Bootstrap 4评分进度条

Doesn't matter the 5, 4, 3... rating. I can easily replace them with font icons.

Here's my code:

 &lt;h4&gt;Ratings and Reviews&lt;/h4&gt;
&lt;div class=&quot;d-flex&quot;&gt;
&lt;div class=&quot;text-center&quot;&gt;
&lt;span class=&quot;display-4 font-weight-bolder&quot;&gt;3.1&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;text-black-50&quot;&gt;out of 5&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;flex-grow-1&quot;&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
5
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
4
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
3
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
2
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
1
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

How do I:

  • Make the progress bar vertically middle align with the text/star.

  • See that I am using Row/Col, but I'd prefer to use flexbox instead.

  • With as minimal CSS as possible.

答案1

得分: 1

Add the class align-items-center to all row elements. By default, rows use flexbox in Bootstrap v4.

英文:

Add the class align-items-center to all row elements. By default, rows use flexbox in Bootstrap v4

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;link href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;h4&gt;Ratings and Reviews&lt;/h4&gt;
&lt;div class=&quot;d-flex&quot;&gt;
&lt;div class=&quot;text-center&quot;&gt;
&lt;span class=&quot;display-4 font-weight-bolder&quot;&gt;3.1&lt;/span&gt;&lt;br&gt;
&lt;span class=&quot;text-black-50&quot;&gt;out of 5&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;flex-grow-1&quot;&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
5
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
4
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
3
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
2
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-4 text-right&quot;&gt;
1
&lt;/div&gt;
&lt;div class=&quot;col-8&quot;&gt;
&lt;div class=&quot;progress&quot; style=&quot;height: 2px;&quot;&gt;
&lt;div class=&quot;progress-bar&quot; role=&quot;progressbar&quot; style=&quot;width: 75%&quot; aria-valuenow=&quot;75&quot; aria-valuemin=&quot;0&quot; aria-valuemax=&quot;100&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2020年1月7日 00:29:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/59615629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定