視頻圍繞布局

Grid Layout body{display: flex;justify-content: center;align-items: center;height:100vh;margin:0;background-color:#f4f4f4; }.container{display: grid;grid-template-columns:repeat(3,100px);/* 3列,每列寬100px */grid-template-rows:repeat(3,100px);/* 3行,每行高100px */gap:10px;/* 每個格子之間的間距 */}.containerdiv{background:#6c8ebf;display: flex;align-items: center;justify-content: center;color: white;font-size:16px; }.container.center{grid-column:2/4;/* 從第2列到第4列 */grid-row:1/3;/* 從第1行到第3行 */}

<!DOCTYPE html>

<html lang="en">

<head>

? <meta charset="UTF-8">

? <meta name="viewport" content="width=device-width, initial-scale=1.0">

? <title>Grid Layout</title>

? <style>

? ? body {

? ? ? display: flex;

? ? ? justify-content: center;

? ? ? align-items: center;

? ? ? height: 100vh;

? ? ? margin: 0;

? ? ? background-color: #f4f4f4;

? ? }

? ? .container {

? ? ? display: grid;

? ? ? grid-template-columns: repeat(3, 100px); /* 3列,每列寬100px */

? ? ? grid-template-rows: repeat(3, 100px);? ? /* 3行,每行高100px */

? ? ? gap: 10px; /* 每個格子之間的間距 */

? ? }

? ? .container div {

? ? ? background: #6c8ebf;

? ? ? display: flex;

? ? ? align-items: center;

? ? ? justify-content: center;

? ? ? color: white;

? ? ? font-size: 16px;

? ? }

? ? .container .center {

? ? ? grid-column: 2 / 4; /* 從第2列到第4列 */

? ? ? grid-row: 1 / 3;? ? /* 從第1行到第3行 */

? ? }

? </style>

</head>

<body>

? <div class="container">

? ? <div>1</div>

? ? <div>2</div>

? ? <div>3</div>

? ? <div>4</div>

? ? <div class="center">5</div>

? ? <div>6</div>

? ? <div>7</div>

? ? <div>8</div>

? ? <div>9</div>

? </div>

</body>

</html>

? grid-template-columns: repeat(3, 100px); /* 3列,每列寬100px */? ??

? grid-template-rows: repeat(3, 100px);? ? /* 3行,每行高100px */

grid-column: 2 / 4;?表示該?div?從第二列開始,跨越到第四列(不包括第四列)。

grid-row: 1 / 3;?表示該?div?從第一行開始,跨越到第三行(不包括第三行)。

這樣設(shè)置后,center類的div將會占據(jù)第一行的第二、三列和第二行的第二、三列位置。希望這可以滿足您的布局要求!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • CSS Grid 網(wǎng)格布局教程 作者: 阮一峰 一、概述 網(wǎng)格布局(Grid)是最強(qiáng)大的 CSS 布局方案。 它將...
    Daeeman閱讀 1,176評論 0 2
  • 一、概述 網(wǎng)格布局(Grid)是最強(qiáng)大的 CSS 布局方案。 它將網(wǎng)頁劃分成一個個網(wǎng)格,可以任意組合不同的網(wǎng)格,做...
    小邊_leo閱讀 375評論 0 1
  • 一、概述 網(wǎng)格布局(Grid)是最強(qiáng)大的 CSS 布局方案。 它將網(wǎng)頁劃分成一個個網(wǎng)格,可以任意組合不同的網(wǎng)格,做...
    硅谷干貨閱讀 541評論 0 14
  • Grid布局是將容器劃分成“行”和“列”,產(chǎn)生單元格,然后指定“項(xiàng)目所在”的單元格,可以看作是二維布局。設(shè)置css...
    keknei閱讀 1,776評論 0 3
  • 前言[#%E5%89%8D%E8%A8%80] 一、概述[#%E4%B8%80%E6%A6%82%E8%BF%B0...
    zoomlaCMS閱讀 1,442評論 0 3

友情鏈接更多精彩內(nèi)容