如何将部分内的垂直拆分布局更改为移动设备上的水平拆分

时间:2018-06-04 03:40:14

标签: html css

双方位于xop-container的区域下,分割是垂直的,但是我似乎无法通过将垂直分割转换为移动视图的水平分割来使媒体查询起作用。

<section class="xop-container">
    <div class="xop-left">
        <div style="text-align: center; background-color:#fcc567; margin-left:20%;margin-right:15%;">
            <p style="font-size:14px; display:inline-block; padding-left:30%; text-align:left;">Lumeca (Pty) Ltd is an<br/> electrical wholesaler.<br/> We supply industries, contractors and<br/> households with electrical<br/> products and equipment required for<br/><br/>

•   Power lines construction and maintenance<br/>
•   High, Medium and Low voltage electrification<br/>
•   Lighting<br/>
•   Cables<br/>
 <br/>
We are a Level 1 BBBEE contributor
</p>
        </div>
    </div>
    <div class="xop-right">
        <div style="text-align: center; background-color:#fcc567; margin-left:20%;margin-right:15%;">
            <p style="font-size:14px; display:inline-block; padding-left:30%; text-align:left;">Lumeca (Pty) Ltd is an<br/> electrical wholesaler.<br/> We supply industries, contractors and<br/> households with electrical<br/> products and equipment required for<br/><br/>

•   Power lines construction and maintenance<br/>
•   High, Medium and Low voltage electrification<br/>
•   Lighting<br/>
•   Cables<br/>
 <br/>
We are a Level 1 BBBEE contributor
</p>
        </div>
    </div>
</section>

CSS具有容器的属性,左右div

.xop-container {
    display: flex;
}

div {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.xop-left {
    background-image: url(../images/city.png);
    background-size: cover;
    background-position: center;
    flex: 1;
    padding: 1rem;
    transition: all .2s ease-in-out;
}

.xop-right {
    background: url(../images/country.png);
    background-size: cover;
    background-position: center;
    flex: 1;
    padding: 1rem;
    transition: all .2s ease-in-out;
    width:100%;
}

媒体查询是针对移动视图的,我为两个视图做过,但都没有。

@media only screen 
and (max-width : 400px) {
    .xop-left {
        width: 100%;
    }
    .xop-right {
        width: 100%;
    }
}
@media (max-width: 750px){
    .xop-container .xop-left{
        width: 100%;
    }
    .xop-container .xop-left{
        width: 100%;
    }
}

我尝试了两种类型的媒体查询,但它们都无法正常工作。我哪里出错了?

2 个答案:

答案 0 :(得分:0)

您需要将display:flex更改为display:block才能正常工作。试试这个媒体查询。

@media (max-width: 750px){
    .xop-container {
      display: block;
    }
    .xop-container .xop-left{
        width: 100%;
    }
    .xop-container .xop-left{
        width: 100%;
    }
}

答案 1 :(得分:0)

如果您想要display: flex xop-container甚至在媒体查询中,那么在主要的css集flex-wrap: nowrap中,然后flex-wrap: wrap在媒体查询中(两者都是这些在xop-container)。

所以,主要的CSS(格式化的道歉,我在手机上):

.xop-container { display: flex; flex-wrap: nowrap; }

然后在媒体查询中:

.xop-container { display: flex; flex-wrap: wrap; }

BTW这是一个关于弹性框的精彩文章:https://css-tricks.com/snippets/css/a-guide-to-flexbox/