簡體   English   中英

具有固定寬度和相等高度的Flex CSS

[英]Flex CSS with fixed width and equal height

我在一個容器中有三個部分。 當我將瀏覽器的大小調整為max-width 668px ,我需要將第1部分和第3部分放在一行中,而在第二行中則放在第2部分中。 第2節的寬度應與第1節和第3節的寬度成比例。

但是現在,一旦我將瀏覽器的大小最小化到668px及以下,則第3部分將不可見。

這就是我嘗試過的。

 @media (max-width: 668px) { .container { display: flex; flex-wrap: wrap; justify-content: center; align-self: flex-start; } .container .section1 { height: 300px; } .container .section1, .container .section3 { flex: 0 0 262px; margin: 3px; display: block; flex-grow: 0; flex-shrink: 0; } .container .section2 { flex: 0 0 500px; flex-grow: 0; flex-shrink: 0; order: 1; min-height: 235px; } } @media (max-width: 940px) { .container { display: flex; flex-wrap: wrap; justify-content: center; align-self: flex-start; } .container .section1 { height: 300px; } .container .section1, .container .section3 { flex: 0 0 262px; margin: 3px; display: block; flex-grow: 0; flex-shrink: 0; } .container .section2 { flex: 0 0 500px; flex-grow: 0; flex-shrink: 0; order: 1; min-height: 235px; } } 
 <div class="container"> <div class="section1">Section 1</div> <div class="section2">Section 2</div> <div class="section3">Section 3</div> </div> 

您在.section3上沒有指定任何高度。

.section1您的height: 300px

.section2您的min-height: 235px

但是在.section3您什么都沒有。 嘗試對您的代碼進行此調整:

.section1, .section3 {
    height: 300px;
}

jsFiddle演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM