Grid网格布局+案例

Grid网格布局

Grid布局是一个二维的布局方法,纵横两个方向总是同时存在。

作用在容器上的:
    display : grid
    grid-template-columns : 设置列数
    grid-template-rows : 设置行数
        fr单位
        repeat()方法
        注:网格中提供了一个新的单位:fr ( 比例单位 )
    grid-template-areas : 划分区域的
        注:区域必须是矩形。
    grid-template:复合写法
        grid-template-rows
        grid-template-columns
        grid-template-areas

        grid-template: 
        "a1 a1 a1" 1fr
        "a3 a3 a2" 1fr
        "a3 a3 a2" 1fr
        /1fr 1fr 1fr;

    grid-column-gap : 列的间距
    grid-row-gap : 行的间距
    grid-gap : 复合写法
        grid-row-gap  grid-column-gap

    justify-items : 子项的水平居中方式
        默认 :  stretch 默认值,拉伸。表现为水平或垂直填充。
        start
        center
        end

    align-items : 子项的垂直居中方式
        默认 :  stretch 默认值,拉伸。表现为水平或垂直填充。
        start
        center
        end
    place-items : 复合写法
        align-items justify-items

    justify-content : 整体网格的水平对齐方式
         默认:stretch
         start
         end
         center
         space-between
         space-around
         space-evenly

    align-content : 整体网格的垂直对齐方式
        默认:stretch
         start
         end
         center
         space-between
         space-around
         space-evenly

    place-content : 复合写法
        align-content justify-content


作用在子项上的:

    grid-area : 找指定的区域
        1.对应网格的名字
        2.写对应的线的数字:grid-area : 1 / 3 / span 2 / 4; 
            grid-row-start / grid-column-start / grid-row-end / grid-column-end

    grid-column-start  水平方向上占据的起始位置
    grid-column-end    水平方向上占据的结束位置
    grid-row-start     垂直方向上占据的起始位置
    grid-row-end       垂直方向上占据的结束位置
        注:只有在grid-column-end和 grid-row-end 中可以设置span操作。span去设置的不是结束位置,而是个数。 
            正常数字是位置,加上span是个数。

    grid-column:3 / 4;
        grid-column-start / grid-column-end
    grid-row:1 / span 2;
         grid-row-start / grid-row-end

    justify-self  单个网格中水平对齐方式
    algin-self单个网格中竖直对齐方式
    place-self复合写法,有顺序(竖直,水平)

实例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    <style>
        *{
   margin: 0;padding: 0;}
        ul{
   list-style: none;}
        a{
   text-decoration: none;color: #77818e;}
        img{
   display: block;}
        .clear:after{
   content: "";display: block;clear: both;}
        html,body{
   height: 100%;}

        #box{height:100%;display: flex;}
        #box .box1{width:250px;}
        #box .box1 div:nth-of-type(1){height: 240px;line-height: 240px;font-size: 26px;color: #77818e;font-family: Arial; padding-left: 24px;}
        #box .box1 div:nth-of-type(2){height: 238px;font-size: 20px;color: #77818e;font-family: Arial;padding-left: 26px;}
        #box .box1 div:nth-of-type(2) li{height: 34px;}
        #box .box1 div:nth-of-type(3){height: 70px;line-height: 72px;font-size: 20px;color: #77818e;font-family: Arial;padding-left: 26px;}
        #box .box1 div:nth-of-type(4){height: 80px;line-height: 86px;font-size: 14px;color: #77818e;}
        #box .box1 div:nth-of-type(4) a{margin-left:22px;}
        #box .box1 div:nth-of-type(5){height: 70px;font-size: 16px;color: #77818e;font-family: Arial;padding-left: 24px;}
        #box .box1 div:nth-of-type(6){height: 52px;line-height: 52px; font-size: 10px;color: #77818e;font-family: Arial;}
        #box .box1 div:nth-of-type(6) a{margin-left: 24px;}</
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值