我是 css 新手,我需要幫助解決一個問題。為什麼 flex-grow 不會將 block__column_2 div 擴展到螢幕末端?根據課程理論,這應該是預期的行為。請告訴我我做錯了什麼?
程式碼範例如下所示。索引.html 樣式.css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>flexbox</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="wrapper"> <div class="block"> <div class="block__row"> <div class="block__column block__column_1"> <div class="block__item">1</div> </div> <div class="block__column"> <div class="block__item block__column_2">2 <br>Более высокий блок </div> </div> <div class="block__column block__column_3"> <div class="block__item">3</div> </div> </div> </div> </div> </body> </html> .wrapper{ height: 100%; overflow: hidden; min-height: 100%; padding: 50px; } body{ font-family: Arial, Helvetica, sans-serif; } .block__row{ border: 20px solid #ece89d; margin: 0px 0px 20px 0px; display: flex; flex-direction: column; height: 1024px; align-items: stretch; } .block__column{ border: 20px solid #5e5373; } .block__column_1{} .block__column_2{ flex-grow: 1; flex-basis: auto; } .block__column_3{} .block__item{ background-color: #18b5a4; padding: 50px; font-size: 50px; color: #fff; font-weight: 700; text-align: center; }
從 div.block__item 中刪除 block__column_2 類別並新增到 div.black_column
並為 block__column 加入 display:flex 父元素上的 display: block 屬性會阻止 flex-grow 產生效果。 嘗試將父級上的 display: block 屬性設為 display: flex。 並添加寬度:100%;到 .block__item