gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 01:35:56 24 4
gpt4 key购买 nike

两侧在一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com