[英]Responsive Web Design: Inner DIV's in a wrapper DIV - Want the inner DIV's to stack on top of each other on mobile devices
I would like the inner div's left
and right
to be centered in the wrapper div at all times, and when the device screen is less than 600 px, the right
inner div to go below the left
inner div. 我希望内部div的left
right
始终保持在包装div的中心,并且当设备屏幕小于600 px时, right
内部div会低于left
内部div。
I have made many attempts to figure it out, but to no avail yet. 我已经做了很多尝试来弄清楚,但是没有用。 All my code is on jsfiddle: 我所有的代码都在jsfiddle上:
https://jsfiddle.net/vdwz3csp/5/ https://jsfiddle.net/vdwz3csp/5/
This is my html code: 这是我的html代码:
<div id="wrap">
<div id="left">
<span>
<img
class="wp-image-440 size-medium aligncenter"
src="http://www.generalgreenestudios.com/wp-content/uploads/2015/09/danielgreene-circle-300x300.png"
alt="Daniel Greene"
width="200"
height="200" />
</span>
<span class="about-desc">
<p style="text-align: center;">
<strong>Daniel Greene</strong>
</p>
<p style="text-align: center;">
Cinematographer/Editor
</p>
<hr style="border-color: #333333;" />
<p style="text-align: justify;">
Text here
</p>
</span>
</div>
<div id="right">
<span>
<img
class="wp-image-435 size-medium aligncenter"
src="http://www.generalgreenestudios.com/wp-content/uploads/2015/09/alexandriagreene-circle-300x300.png"
alt="Alexandria Greene"
width="200"
height="200" />
</span>
<span class="about-desc">
<p style="text-align: center;">
<strong>Alexandria Greene</strong>
</p>
<p style="text-align: center;">
Accounts/Client Relations
</p>
<hr style="border-color: #333333;" />
<p style="text-align: justify;">
Some text goes here
</p>
</span>
</div>
</div>
This is my css code: 这是我的CSS代码:
#wrap {
display: flex;
justify-content: center;
width: 100%;
}
#left, #right {
padding: 20px;
width:25%;
min-width:300px;
float:left;
}
@media screen and (max-width: 600px) {
#left {
float:none;
width:auto;
margin:0 auto;
}
#right {
float:none;
width:auto;
margin:50px auto;
}
}
Try using flex-direction
尝试使用flex-direction
updated fiddle: https://jsfiddle.net/vdwz3csp/7/ 更新的提琴: https : //jsfiddle.net/vdwz3csp/7/
#wrap {
display: flex;
justify-content: center;
flex-direction:row;
width: 100%;
}
#left, #right {
padding: 20px;
width:25%;
min-width:300px;
}
@media screen and (max-width: 600px) {
#wrap
{
flex-direction:column;
}
}
只是交换display
的的#wrap
从flex
为纯block
中移动的查询: https://jsfiddle.net/vdwz3csp/8/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.