如您所见,两个卡盒不在中间。我尝试了一些操作,请参见下面的代码。希望您能帮帮我!预先谢谢你!
<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>
答案 0 :(得分:1)
只需将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">