使用卡片和 for 循环引导

Bootstrapping with card and for loop

我正在尝试在我的 .html 中实现卡片引导,但我无法将其居中。请查看下面的代码并帮助

<h1> 10 Games Recommended Based on {{ selected }} </h1>

        <div class = "container">
        
        <div class="recommendations">
  
            {% for name in names_list %}
            <div class="card-group">
                <div class="card text-center" style="Max-width: 30%;">
                  <!-- <img src="..." class="card-img-top" alt="..."> -->
                  <div class="card-body">
                    <h5 class="card-title"> <a href = "{{ games[name]['url'] }}" target = "popup">{{ name }}</a></h5>
                    <div class = 'card-body'>
                        <p1 class = "card-text">Overall Reviews: {{games[name]['rating'] }}</p1>
                    </div>
                  </div>
                </div>
            </div>
            {% endfor %}
        
        </div>
        </div>

对于混乱,我深表歉意,但我的应用程序提供结果的方式被推到了左边,就像 this。

我的风格如下

<style>
            p {font-size: 30px;}
            p1 {font-size: 13px;}
            a {color:navy;
                font-size: 20px;}
            body {text-align: center;}
            body {background-color: lightblue;}        
</style>

无论如何我可以在使用循环时将它们居中或并排对齐吗?

您缺少 .row.col 类。添加它们即可。

<h1>10 Games Recommended Based on {{ selected }}</h1>

<div class="container">
  <div class="row">
    <div class="recommendations">
      {% for name in names_list %}
      <div class="col-3">
        <div class="card-group">
          <div class="card text-center" style="max-width: 30%">
            <!-- <img src="..." class="card-img-top" alt="..."> -->
            <div class="card-body">
              <h5 class="card-title">
                <a href="{{ games[name]['url'] }}" target="popup">{{ name }}</a>
              </h5>
              <div class="card-body">
                <p1 class="card-text"
                >Overall Reviews: {{games[name]['rating'] }}</p1
                >
              </div>
            </div>
          </div>
        </div>
      </div>
      {% endfor %}
    </div>
  </div>
</div>

请注意,.col-3 应该是重复的,.row 应该是父级。