寒假学习记录11:grid布局

css 复制代码
display:grid
css 复制代码
grid-template-columns: 100px 100px 100px  //指定每列的宽度
grid-template-rows: 100px 100px 100px    //指定每行的宽度
css 复制代码
column-gap: 24px    //列间距
row-gap: 24px    //行间距
gap: 24px    //都设置

4.grid-template-areas用法

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .container{
        width: 100px;
        display: grid;
        grid-template-areas: 
            "header header header"
            "sidebar content content"
            "footer footer footer";
        gap: 10px;
    }
    header{
        width: 1fr; height: 30px;
        grid-area: header;
        background-color: red;
    }
    main{
        width: 60px; height: 50px;
        grid-area: content;
        background-color: aqua;
    }
    aside{
        width: 40px; height: 50px;
        grid-area: sidebar;
        background-color: green;
    }
    footer{
        width: 1fr; height: 30px;
        grid-area: footer;
        background-color: blue;
    }
</style>
<body>
    <div class="container">
        <header></header>
        <aside></aside>
        <main></main>
        <footer></footer>
    </div>
</body>
</html>

效果

align和justify和flex一样

grid特有的浮动单位:fr

长度为 当前fr / 总fr

相关推荐
刘发财31 分钟前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶3 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶3 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol6 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路7 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide7 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter7 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸8 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live000009 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉9 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化