码迷,mamicode.com
首页 > Web开发 > 详细

CSS grid layout demo 网格布局实例

时间:2018-01-10 20:16:27      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:col   name   ack   target   family   space   scala   pre   ems   

直接 上代码,里面我加注释,相当的简单, 也可以去我的github上直接下载代码,顺手给个星:https://github.com/yurizhang/micro-finance-admin-system/blob/master/grid.html

 

<!DOCTYPE html>
<html>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui">
<meta content=yes name=apple-mobile-web-app-capable>
<meta content=yes name=apple-touch-fullscreen>
<meta content="telephone=no,email=no" name=format-detection>

<head>
    <title>Gird示例</title>
    <style>
        body,
        html {
            padding: 0;
            margin: 0;
        }

        .wrapper {
            display: grid;
            grid-template-columns: 1fr 1fr;
            /*表示2列*/
            grid-template-rows: 1fr 2fr 1fr 2fr;
            /*第二行的高是第一行的2倍,我们现在可以设置行高之间的关系。如果我们把前面的行高设成 1fr ,最后一个则设置为 3fr,这意味着第二行的行高是第一行的 3 倍:*/
            grid-column-gap: 1px;
            /*列之间的线*/
            grid-row-gap: 1px;
            /*行之间的线隔*/
            background-color: rgb(117, 112, 112);
        }

        @media screen and (min-width: 500px) {
            /*超过500显示三列*/
            .wrapper {
                grid-template-columns: 1fr 1fr 1fr;
            }
        }

        @media screen and (min-width: 800px) {
            /*超过800四列*/
            .wrapper {
                grid-template-columns: 1fr 1fr 1fr 1fr;
            }
        }

        .letter {
            background-color: #0069b3;
            display: flex;
            justify-content: center;
            /*flex的相差属性居中对齐*/
            align-items: center;
            /*容器里元素垂直居中*/
            padding: 20px;
            font-size: 70px;
            color: white;
            line-height: 1;
            font-family: ‘hobeaux-rococeaux-background‘, Helvetica;
            font-weight: 200;
            cursor: pointer;
            transition: all .3s ease;
        }
    </style>
</head>

<body>
    <div class="wrapper">
        <div class="letter">
            Aa
        </div>

        <div class="letter">
            Bb
        </div>

        <div class=‘letter‘>
            Cc
        </div>
        <div class=‘letter‘>
            Dd
        </div>
        <div class="letter">
            Ee
        </div>

        <div class="letter">
            Ff
        </div>

        <div class=‘letter‘>
            Gg
        </div>
        <div class=‘letter‘>
            Hh
        </div>
        <div class="letter">
            Ii
        </div>

        <div class="letter">
            Jj
        </div>

        <div class=‘letter‘>
            Kk
        </div>
        <div class=‘letter‘>
            Mm
        </div>

    </div>
</body>

</html>

效果如下:

 

技术分享图片技术分享图片技术分享图片

<!DOCTYPE html>
<html>
<meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui">
<meta content=yes name=apple-mobile-web-app-capable>
<meta content=yes name=apple-touch-fullscreen>
<meta content="telephone=no,email=no" name=format-detection>

<head>
<title>Gird示例</title>
<style>
body,
html {
padding: 0;
margin: 0;
}

.wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
/*表示2列*/
grid-template-rows: 1fr 2fr 1fr 2fr;
/*第二行的高是第一行的2倍,我们现在可以设置行高之间的关系。如果我们把前面的行高设成 1fr ,最后一个则设置为 3fr,这意味着第二行的行高是第一行的 3 倍:*/
grid-column-gap: 1px;
/*列之间的线*/
grid-row-gap: 1px;
/*行之间的线隔*/
background-color: rgb(117, 112, 112);
}

@media screen and (min-width: 500px) {
/*超过500显示三列*/
.wrapper {
grid-template-columns: 1fr 1fr 1fr;
}
}

@media screen and (min-width: 800px) {
/*超过800四列*/
.wrapper {
grid-template-columns: 1fr 1fr 1fr 1fr;
}
}

.letter {
background-color: #0069b3;
display: flex;
justify-content: center;
/*flex的相差属性居中对齐*/
align-items: center;
/*容器里元素垂直居中*/
padding: 20px;
font-size: 70px;
color: white;
line-height: 1;
font-family: ‘hobeaux-rococeaux-background‘, Helvetica;
font-weight: 200;
cursor: pointer;
transition: all .3s ease;
}
</style>
</head>

<body>
<div class="wrapper">
<div class="letter">
Aa
</div>

<div class="letter">
Bb
</div>

<div class=‘letter‘>
Cc
</div>
<div class=‘letter‘>
Dd
</div>
<div class="letter">
Ee
</div>

<div class="letter">
Ff
</div>

<div class=‘letter‘>
Gg
</div>
<div class=‘letter‘>
Hh
</div>
<div class="letter">
Ii
</div>

<div class="letter">
Jj
</div>

<div class=‘letter‘>
Kk
</div>
<div class=‘letter‘>
Mm
</div>

</div>
</body>

</html>

CSS grid layout demo 网格布局实例

标签:col   name   ack   target   family   space   scala   pre   ems   

原文地址:https://www.cnblogs.com/yuri2016/p/8260146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!