亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不均勻的 CSS 列網格

不均勻的 CSS 列網格

揚帆大魚 2023-02-17 15:51:10
從我對這個問題的研究中,我了解到 CSS 網格似乎能夠處理相當復雜的行為。我的場景更簡單,我希望有 4 個均勻間隔的面板框,代碼如下。我的問題是為什么水平間隙不在垂直中間居中?我通過 trail&error 來測試對齊、對齊和網格規范的各種組合,但找不到解決方案。我需要在我的代碼中添加什么才能使間隙在頁面上垂直居中?.main-container {    display: grid;    grid-template-columns: repeat(2, 1fr);    grid-gap: 20px;    height: 100vh;    align-items: stretch;    margin: 0;    padding: 0;    justify-content: space-between;}.container {    border: 3px solid black;    display: flex;    position: relative;    flex-direction: column;    margin: 0;    padding: 0;}.shared {    justify-content: center;    border: none;}.sub-container {    border: 3px solid black;    align-items: stretch;    height: 100%;    margin: 0;    padding: 0;} <div class="main-container">    <div class="container" id="A">        <h1>Section A</h1>        <p id="A-values">A Values</p>    </div>    <div class="container" id="B">        <h1>Section B</h1>        <p id="B-values">B Values</p>    </div>    <div class="container" id="C">        <h1>Section C</h1>        <p id="C-values">C Values</p>    </div>    <div class="container shared" id="D">        <div class="sub-container">            <h2>SubSection D1</h2>            <p id="D1-values">D1 Values</p>        </div>        <div class="sub-container">            <h2>SubSection D2</h2>            <p id="D2-values">D2 Values</p>        </div>        <div class="sub-container">            <h2>SubSection D3</h2>            <p id="D3-values">D3 Values</p>        </div>    </div></div>
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

默認情況下,高度設置為與一行中最長的項目相匹配,底部行的高度與頂部的高度不同只是因為其中一列中有更多內容。

嘗試設置行,因為你有列,添加grid-template-rows: repeat(2, 1fr);main-container班級


查看完整回答
反對 回復 2023-02-17
  • 1 回答
  • 0 關注
  • 113 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號