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

标签 html css

两侧在一个 xop-container 部分下,分割是垂直的,但是我似乎无法通过将垂直分割转换为移动 View 的水平分割来使媒体查询工作。

<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%;
}

媒体查询是针对移动 View 的,我对两个 View 都做了,但都不起作用。

@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%;
    }
}

我尝试了两种类型的媒体查询,但它们都不起作用。我哪里出错了?

最佳答案

您需要将 display:flex 更改为 display:block 并且它可以正常工作。试试这个媒体查询。

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

关于html - 如何将部分内的垂直拆分布局更改为移动设备上的水平拆分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50673141/

相关文章:

jquery - 为什么我不能选择 use .play() 使用 jQuery 选择视频?

CSS 网格 : centering and overlapping difficulties

css - 1pt有多大?

java - 带有数据输入的 PHP/JavaScript 网络交互式 map 集?

javascript - Angular-Dialog-Service 和模态代码的可读性

javascript - 仅通过单击元素激活菜单

html - Mozilla 和 IE 中的填充问题

javascript - 如何检查/删除元素?

CSS - 均匀拉伸(stretch) block

html - 如何使用 CSS 使按钮居中?