gpt4 book ai didi

html - Bootstrap 3 - 列不会居中对齐

转载 作者:太空宇宙 更新时间:2023-11-04 01:00:24 25 4
gpt4 key购买 nike

我正在尝试将三个 Bootstrap 列居中对齐。我不希望列跨越整行。我认为这会使图像看起来对于空间来说太大了。这就是我放置三个“col-md-3”列的原因。我更喜欢这个尺码栏。我只希望列居中对齐。我以为我可以将类名“justify-content-md-center”应用到该行,它会起作用,但它不起作用。有谁知道如何使用 Bootstrap 3 将下面的列居中对齐?可能吗?

这是我的代码:

<div class="container">
<div class="row justify-content-md-center">

<div class="col-md-3 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

<div class="col-md-3 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

<div class="col-md-3 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

</div><!-- end row -->
</div><!-- end container -->

CodePen 上查看.

谢谢你的帮助!

最佳答案

正如其他人所指出的,将 col-md-3 更改为 col-md-4

I do not want the columns to span the entire row. I think that will make the images look too big for the space.

我知道的 Bootstrap 3 解决方案是将 max-width 添加到容器中,这样它就不会拉伸(stretch)整个屏幕/元素(无需从图像中删除 100%将不再使它们调整大小/响应)。

您可能还想使用 col-sm-4 或 col-sm-6,这样当屏幕较小时它们不会太大:

https://codepen.io/StudioKonKon/pen/yQQrdM

.mycontent
{
max-width: 800px; /* or something else */
}
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">



<div class="container mycontent">
<div class="row justify-content-md-center">

<div class="col-md-4 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

<div class="col-md-4 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

<div class="col-md-4 text-center">
<img alt="TBD" width="100%" src="https://via.placeholder.com/150" />
</div>

</div><!-- end row -->
</div><!-- end container -->

关于html - Bootstrap 3 - 列不会居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53546520/

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