盒子模型以及布局

2022-10-24  本文已影响0人  山猪打不过家猪

使用margin和padding的原则

作者:学致编程
链接:https://www.zhihu.com/question/395374225/answer/1231999824
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

1.margin

image.png

2.padding

image.png

3.布局

image.png
image.png
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #top{
            width: 100%;
            height: 15px;
            background: black;
        }
        #header{
            width: 1005px;
            height: 50px;
            background: #e83828;
            margin: auto;
        }
        #head{
            width: 500px;
            height: 50px;
            background:#D1D3D6;
            margin: auto;
        } 
        #banner{
            width: 1005px;height: 300px;
            background: slateblue;
            margin: auto;
        }
        #wrapper-category{
            width:1005px;height: 150px;
            margin: auto;
        }
        #category{
            width:687px;height: 150px;
            margin: auto;
            background:#D1D3D6;
        }
        #category .item{
            width:100px; height:120px;
            border-right: 1px dashed black;
            margin-top: 15px;
            padding-left: 8px;
            padding-right: 8px;
            float: left;
        }
        #category .item.last{
            border-right: 0;
            padding-right: 0;
        }
        #category .item.first{
         
            padding-left: 0;
        }
        #case{
            width: 1005px;height: 300px;
            margin: auto;
            background: #eeeeee;
        }
        #case .titel-text{
            width: 687px;
            font-size: 30px;
            margin: auto;
            padding-top: 20px;
            padding-bottom: 5px;
        }
        #case .wrapper{
            width: 687px;
            height: 200px;
            margin: auto;
        }
        #case .wrapper .item{
            width: 222px;
            height: 200px;
            background: #9acd32;
            float: left;
        }
        #case .wrapper .item.md{
            margin-left:10px;
            margin-right:10px;
        }
        #case p{
            margin-top: 5px;
            font-size: 15px;
            text-align: center;
        }
        #case p a{
            text-decoration: None;
            color: dimgray;
        }
    </style>
</head>
<body>
    <div id="top"></div>

    <div id="header">
        <div id="head"></div>
    </div>

    <div id="banner"></div>

    <div id="wrapper-category">
        <div id="category">
            <div class="item first"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item last"></div>
        </div>
    </div>
    
    <div id="case">
        <div class="titel-text">Case</div>
        <div class="wrapper">
            <div class="item"></div>
            <div class="item md"></div>
            <div class="item"></div>
        </div>
        <p><a href="">查看更多...</a></p>
    </div>
</body>
</html>
image.png

3.绝对定位,相对定位,固定定位

image.png
image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读