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

标签 html css twitter-bootstrap-3

我正在尝试将三个 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/

相关文章:

html - 边距和填充(我猜)在浏览器中有所不同

javascript - 将 div 绑定(bind)到另一个 div 的右边框

html - 在滚动条上反转/更改 Logo

css - Twitter Bootstrap 3 - 在词缀滚动上丢失容器全宽

javascript - 如何将数据从node js传递到html?

PHP 提交按钮不起作用。

html - 链接标签中的颜色不起作用,但链接标签中的 div 颜色有效?

javascript - jQuery Cookie 故障

css - Bootstrap 3 中文本变得可点击和样式改变的奇怪行为

html - 问题设计 Bootstrap 导航栏