响应式栅栏布局

任务八 : 响应式网格(栅格化)布局


目标:实现效果如图

效果图

知识点

  • CSS3 属性 box-sizing 的使用: 当元素的宽度、高度确定时, { box-sizing : border-box }将元素的padding, border都将在设定的高度和宽度内绘制;也就是说,无论你的padding和border如何变化,它都不会超出预先设定好的宽度和高度.

  • 清楚浮动防止高度塌陷: 设外层元素为container, 内层为content,应用了float属性的内层元素content高度一旦超过container,container就无法完全包裹content,就造成了高度塌陷.解决办法:父级元素应用::after选择器.
        .container: after {
            content: " ";
            display: table;
            clear: both;
        }

本次练习代码示例:

index.html文件:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="./public/index.css">
    <title></title>
</head>
<body>
    <div class="row">
        <div class="col-md-4 col-sm-6">
            <div class="content"></div>
        </div>
        <div class="col-md-4 col-sm-6">
            <div class="content"></div>
        </div>
        <div class="col-md-4 col-sm-12">
            <div class="content"></div>
        </div>
        <div class="col-md-3 col-sm-3">
            <div class="content"></div>
        </div>
        <div class="col-md-6 col-sm-6">
            <div class="content"></div>
        </div>
        <div class="col-md-3 col-sm-3">
            <div class="content"></div>
        </div>
        <div class="col-md-1 col-sm-2">
            <div class="content"></div>
        </div>
        <div class="col-md-1 col-sm-2">
            <div class="content"></div>
        </div>
        <div class="col-md-2 col-sm-8">
            <div class="content"></div>
        </div>
        <div class="col-md-2 col-sm-3">
            <div class="content"></div>
        </div>
        <div class="col-md-6 col-sm-3">
            <div class="content"></div>
        </div>
    </div>
</body>
</html>

master.css文件

      * {
    box-sizing: border-box;
}

[class*= 'col-'] {
    float: left;
    height: 70px;
    padding: 10px;
}

.content {
    border: 1px solid #999;
    background-color: #eee;
    height: 50px;
}

@media only screen and (min-width: 768.1px) {
    .col-md-1 {
        width: 8.333%;
    }
    .col-md-2 {
        width: 16.666%;
    }
    .col-md-3 {
        width: 25%;
    }
    .col-md-4 {
        width: 33.333%;
    }
    .col-md-5 {
        width: 41.666%;
    }
    .col-md-6 {
        width: 50%;
    }
    .col-md-8 {
        width: 66.666%;
    }
    .col-md-12 {
        width: 100%;
    }
}

@media only screen and (max-width: 768px) {
    .col-sm-1 {
        width: 8.333%;
    }
    .col-sm-2 {
        width: 16.666%;
    }
    .col-sm-3 {
        width: 25%;
    }
    .col-sm-4 {
        width: 33.333%;
    }
    .col-sm-5 {
        width: 41.666%;
    }
    .col-sm-6 {
        width: 50%;
    }
    .col-sm-8 {
        width: 66.666%;
    }
    .col-sm-12 {
        width: 100%;
    }
}

.row:after {
    display: table;
    content: " ";
    clear: both;
}

(如有错漏 欢迎指正);

转载于:https://www.cnblogs.com/sysuhanyf/p/5310412.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值