调整屏幕大小时,Bootstrap 4列未堆叠

时间:2018-06-14 14:43:39

标签: css twitter-bootstrap

当我调整屏幕大小时,我似乎无法理解为什么div不会叠加在一起。 我使用col-xs-4 col-md-4 col-lg-4,但内容保持在一行,甚至没有调整大小。

    <div class="container">
    <div class="row">
        <div class="info">
            <div class="col-xs-4 col-md-4 col-lg-4">
                <div class="logo-link"><img alt="Spartan Safety Logo" class="img-fluid" src="img/logo.png">
                </div>
            </div>


            <div class="col-xs-4 col-md-4 col-lg-4">
                <div class="info-center-1">
                    <div class="info-center-icon">
                        <i class="fa fa-phone-square fa-2x"></i>
                    </div>


                    <div class="info-center-title">
                        <h6>Customer Support and Sales</h6>
                    </div>


                    <div class="info-center-text">
                        <p>0208 5275888</p>
                    </div>
                </div>
            </div>


            <div class="col-xs-4 col-md-4 col-lg-4">
                <div class="info-center-1">
                    <div class="info-center-icon">
                        <i class="fa fa-clock-o fa-2x"></i>
                    </div>


                    <div class="info-center-title">
                        <h6>Opening Hours</h6>
                    </div>


                    <div class="info-center-text">
                        <p>Mon - Fri 08:30 - 4:30</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

CSS

  .info {
        display: inline-flex;
        margin: 20px 0px 10px 0px;
}

    .logo-link img {
        max-width: 50%;
        height: auto;
        margin-bottom: 10px;
}

    .info-center-1 {
        margin-top: 20px;
}

.info-center-icon i {
        color: #cccccc;
        display: inline-flex;
}

.info-center-title {
        margin-bottom: px;
}

.info-center-title h6 {
        font-family: 'Open Sans', Helvetica, Arial, sans-serif;
        font-size: 16px;
        font-weight: 400;
        font-style: normal;
        line-height: 22px;
        text-transform: uppercase;
        display: inline-flex;
}

.info-center-text p {
        font-family: 'Open sans', sans-serif;
        font-size: 24px;
        font-weight: 400;
        color: #FF9900;
        line-height: 22px;
        display: inline-flex;
}

2 个答案:

答案 0 :(得分:0)

您不应在.row.col-之间添加更多div。相反,合并inforow,这样您只有col- div的一个包装器:

   <div class="container">
<div class="row info">
        <div class="col-xs-4 col-md-4 col-lg-4">
            <div class="logo-link"><img alt="Spartan Safety Logo" class="img-fluid" src="img/logo.png">
            </div>
        </div>


        <div class="col-xs-4 col-md-4 col-lg-4">
            <div class="info-center-1">
                <div class="info-center-icon">
                    <i class="fa fa-phone-square fa-2x"></i>
                </div>


                <div class="info-center-title">
                    <h6>Customer Support and Sales</h6>
                </div>


                <div class="info-center-text">
                    <p>0208 5275888</p>
                </div>
            </div>
        </div>


        <div class="col-xs-4 col-md-4 col-lg-4">
            <div class="info-center-1">
                <div class="info-center-icon">
                    <i class="fa fa-clock-o fa-2x"></i>
                </div>


                <div class="info-center-title">
                    <h6>Opening Hours</h6>
                </div>


                <div class="info-center-text">
                    <p>Mon - Fri 08:30 - 4:30</p>
                </div>
            </div>
        </div>
</div>

工作示例:http://jsfiddle.net/aq9Laaew/34182/

答案 1 :(得分:0)

如果您希望列获取特定屏幕大小的行的整个宽度,则应指定col-ScreenSize-12。所以你应该使用col-xs-12 col-md-4 col-lg-4代替。 并且还显示:inline-flex;类.info上的样式使得除法总是在单行中,因此将其删除。