【问题标题】:how to center the div如何使div居中
【发布时间】:2014-10-09 17:56:52
【问题描述】:

我想将容器内 div 的所有内容居中。 我尝试使用margin 0 auto,但没有用 我怎样才能把它居中?

    <div class="container">
    <div class="text-center" style="margin:0 auto;overflow:auto;">
       <div style="float:left;width:15%;margin-right:2px;">

            <img src="PICTURES/Bruce-Crocker_311x312(2).jpg" class="img-responsive" />
            <div class="contenthover">
                <p>bla</p>
            </div>
       </div>
        <div style="float:left;width:15%;margin-right:2px;">

            <img src="PICTURES/Bruce-Crocker_311x312(2).jpg" class="img-responsive" />
            <div class="contenthover">
                <p>bla</p>
            </div>
       </div>


    </div>

谁能帮忙?

【问题讨论】:

    标签: html twitter-bootstrap responsive-design


    【解决方案1】:

    在要居中的任何块元素上使用 Bootstrap center-block 类,对文本使用 text-center..

    <div class="container">
        <div>
                <img src="PICTURES/Bruce-Crocker_311x312(2).jpg" class="center-block img-responsive">
                <div class="text-center">
                    <p>bla</p>
                </div>
        </div>
    </div>
    

    http://www.bootply.com/65YSFBl6mF

    【讨论】:

    • 谢谢,不过如果你想加一个div就好了,如果你用float:left添加更多的div就不行了。
    猜你喜欢
    • 1970-01-01
    • 2015-09-12
    • 2013-02-27
    • 2017-01-18
    • 2014-04-11
    • 2015-02-10
    • 2011-05-23
    • 2012-01-24
    • 1970-01-01
    相关资源
    最近更新 更多