前端学习总结【102天】:CSS——响应式网格(栅格化)布局的HTML、CSS实现

关键知识

1.box-sizing: border-box;不可继承

2.浮动布局:子元素float:left;

3.清除浮动的方式

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

4.媒体查询:@media(min-width:768px){

.col-md-1 {
       background:red;
   }

}

5.calc使用方法

width: calc(8.3% - 20px);

我的代码

<!DOCTYPE html>
<html>
<head>
    <title>IFE08</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/normalize.css">
    <link rel="stylesheet" href="css/IFE08.css">
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-4">col-md-4</div>
            <div class="col-md-4">col-md-4</div>
            <div class="col-md-4">col-md-4</div>
        </div>
        <div class="row">
            <div class="col-md-3">col-md-3</div>
            <div class="col-md-6">col-md-6</div>
            <div class="col-md-3">col-md-3</div>
        </div>
        <div class="row">
            <div class="col-md-1">col-md-1</div>
            <div class="col-md-1">col-md-1</div>
            <div class="col-md-2">col-md-2</div>
            <div class="col-md-2">col-md-2</div>
            <div class="col-md-6">col-md-6</div>
        </div>
    </div>
</body>
</html>
.container {
    padding: 10px;
}

.row {
    margin-bottom: 20px; 
}

.row > div {
    border: solid 1px #999;
    background: #eee;
    height: 50px;
    margin: 10px;
    box-sizing: border-box;

}

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

@media (min-width: 768px) {
        
    .col-md-1 {
        width: calc(8.333333% - 20px);
    }
    .col-md-2 {
        width: calc(16.6666667% - 20px);
    }
    .col-md-3 {
        width: calc(25% - 20px);
    }
    .col-md-4 {
        width: calc(33.3333333% - 20px);
    }
    .col-md-6 {
        width: calc(50% - 20px);
    }

    .col-md-1,
    .col-md-2,
    .col-md-3,
    .col-md-4,
    .col-md-6 {
        float: left;
    }

}

相关推荐