gpt4 book ai didi

html - 如何在父 div 中居中放置多个 div?

转载 作者:行者123 更新时间:2023-11-28 10:38:41 25 4
gpt4 key购买 nike

我在一个父 div 中包含 3 个 div (class="row services")。

我怎样才能使三个 col s12 l3 div 集中在这个父 div 中?

我试过使用 display:blocktext-align:center 但这似乎没有效果。

HTML:

<div class="row services">

<div class="col s12 l3">
<div class="divider"></div>
<h5><p>Nelson Mazda Tulsa</p> <p>Tulsa, OK</p></h5>
<p>9902 S. Memorial Dr.</p>
<p>Tulsa, OK 74133</p>
<p>866-612-0040</p>
<a href="http://www.nelsonmazdaok.com/mazda-dealer-tulsa-ok/car-dealership-near.html" class="btn waves-effect waves-dark white black-text">Get Directions</a>
<p>
<a href="http://www.nelsonmazdaok.com/" class="btn waves-effect waves-dark white black-text">Visit Website</a>
</div>

<div class="col s12 l3">
<div class="divider"></div>
<h5><p>Nelson Mazda Hickory Hollow</p> <p>Antioch, TN</p></h5>
<p>5300 Mount View Road</p>
<p>Antioch, TN 37013</p>
<p>877-708-4449</p>
<a href="http://www.nelsonmazdahh.com/nelson-difference/car-dealership-near.html" class="btn waves-effect waves-dark white black-text">Get Directions</a>
<p>
<a href="http://www.nelsonmazdahh.com/" class="btn waves-effect waves-dark white black-text">Visit Website</a>
</div>

<div class="col s12 l3">
<div class="divider"></div>
<h5><p>Nelson Mazda Cool Springs</p> <p>Franklin, TN</p></h5>
<p>7104 S Springs Drive</p>
<p>Franklin, TN 37067</p>
<p>877-708-4456</p>
<a href="http://www.nelsonmazdacs.com/nelson-difference/car-dealership-near.html" class="btn waves-effect waves-dark white black-text">Get Directions</a>
<p>
<a href="http://www.nelsonmazdacs.com/" class="btn waves-effect waves-dark white black-text">Visit Website</a>
</div>

</div>

CSS:

enter image description here

最佳答案

使用 CSS Flexbox 可以轻松居中。

这就是你所需要的:

.row {
display: flex;
flex-direction: column;
align-items: center;
}

DEMO

更多 flexbox 居中选项:https://stackoverflow.com/a/33049198/3597276

关于html - 如何在父 div 中居中放置多个 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35004676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com