2016-11-14 17 views
1

我有2個DIVs並已將它們排列在一起。如果我最小化了我的屏幕(例如,如果屏幕寬度爲400px),我希望DIV在另一個之下對齊。2 Div並排=>屏幕最小=> 1下另一個

我該怎麼做?謝謝。

#parent { 
 
    width: 100%; 
 
    display: flex; 
 
} 
 

 
#section1 { 
 
    width: 50%; 
 
    background-color: red; 
 
} 
 

 
#section2 { 
 
    width: 50%; 
 
    background-color: lightblue; 
 
}
<div id="parent"> 
 
    <div id="section1"> 
 
    Section 1/ Section 1/ Section 1/ Section 1/Section 1/ Section 1/ Section 1/ Section 1 
 
    </div> 
 
    <div id="section2"> 
 
    Section 1/ Section 1/ Section 1/ Section 1/Section 1/ Section 1/ Section 1/ Section 1 
 
    </div> 
 
</div>

+0

查看媒體查詢 – j08691

+1

請閱讀[問]。重要短語:「搜索和研究」和「解釋......阻止你自己解決它的任何困難」。 –

回答

0

您將要產生最大寬度媒體查詢:400像素。 CSS看起來像這樣:

@media (max-width: 400px) { 
    #parent { 
     display: block; 
    } 
} 

這是fiddle

相關問題