通过引导程序将卡片盒放在中间

问题描述 投票:0回答:1

我有问题。我要刷卡(请看图片)picture

如您所见,两个卡盒不在中间。我尝试了一些操作,请参见下面的代码。希望您能帮帮我!预先谢谢!

 <div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
        <div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
            <div class="row padding">
                <div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
                    <div class="card" style="width: 18rem; margin-left: 1%; ">
                        <img class="card-img-top" src="img\festival-tickets\ticket3.png">
                        <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-outline-secondary">Go somewhere</a>
                        </div>
                      </div>
                </div>
                <div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
                    <div class="card" style="width: 18rem;">
                        <img class="card-img-top" src="img\festival-tickets\ticket3.png">
                        <div class="card-body">
                          <h5 class="card-title">Card title</h5>
                          <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
                          <a href="#" class="btn btn-outline-secondary">Go somewhere</a>
                        </div>
                      </div>
                </div>
            </div>
        </div>
    </div>
html css bootstrap-4
1个回答
0
投票

只需在要居中的元素(在本例中为卡片)的父元素(即justify-content: center;)上添加.row .padding

.center {
  justify-content: center;
}
<div class="test" style="margin-left: auto; margin-right:auto; text-align: center; position: relative;">
  <div class="container-fluid padding" style="margin-left: auto; margin-right:auto;">
    <div class="row padding center">
      <div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
        <div class="card" style="width: 18rem; margin-left: 1%; ">
          <img class="card-img-top" src="img\festival-tickets\ticket3.png">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-outline-secondary">Go somewhere</a>
          </div>
        </div>
      </div>
      <div class="cold-md-4" style="margin-right: 1%; margin-left: 1%; margin-top: 1%; margin-bottom: 1%;">
        <div class="card" style="width: 18rem;">
          <img class="card-img-top" src="img\festival-tickets\ticket3.png">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-outline-secondary">Go somewhere</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
© www.soinside.com 2019 - 2024. All rights reserved.