【问题标题】:centering an image on only small screens with twitter bootstrap仅使用 twitter bootstrap 将图像居中在小屏幕上
【发布时间】:2015-06-05 06:59:28
【问题描述】:

我有一个图像,我试图在 div 中间居中,但只能在使用 twitter bootstrap 的 xs 屏幕上。

在小屏幕和大屏幕上,布局如下所示:

当它进入 xs 屏幕时,它看起来像这样:

当文本在 xs 屏幕上从页面上掉下来时,我希望图像居中。

这个 div 的 html 是这样的:

HTML

        <div class="row">
                <div class="col-md-8 col-md-offset-2 col-sm-10 col-sm-offset-1">
                    <div class="col-xl-4 col-md-5 col-sm-6 col-xs-12">
                        <div class="img">
                        </div>
                    </div>
                    <div class="col-xl-8 col-md-7 col-sm-6 col-xs-12">
                        <div class="info">  
                        </div>
                        <div class="icons">
                            <ul class="list-inline icon-list">
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

img div 是包含我想在小屏幕上居中的图像的那个。

我尝试了以下 CSS,但它不起作用:

CSS

.col-xs-12  > .img img {
display: block;
margin: 0, auto !important;
}

我不清楚为什么这不起作用。

【问题讨论】:

  • 跑题了,但那是真正的产品吗?!
  • 去掉margin的逗号
  • @jurgemaister - 是的。 link

标签: css twitter-bootstrap


【解决方案1】:

只需 text-align 在具有类 img 的 div 列上。出于实际原因,使用 centered 类调用它

.centered {
    text-align:center;
}

https://jsfiddle.net/udwtavzh/2/

【讨论】:

  • 我为我的构建添加了自定义类,在本例中为“xs-center”。如果它是块级元素,我将应用以下内容: .xs-center { margin: 0 auto; } 热爱产品品牌!
  • 我像你一样添加了居中的类,但我的图像总是在屏幕的中心,而不仅仅是小屏幕。
猜你喜欢
  • 2020-10-07
  • 2013-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多