CSS学习(十七)-盒模型

一、理论:
1.CSS盒模型
a.外盒尺寸计算--高度
element空间高度=内容高度+内距+边框+边距
b.外盒尺寸计算--宽度 element空间宽度=内容宽度+内距+边框+外距
c.内盒尺寸计算--高度
element高度=内容高度+内距+边框
d.内盒尺寸计算--宽度
element宽度=内容宽度+内距+边框
2.box-sizing
a.content-box 默认值
b.border-box 元素维持IE传统的盒模型
c.inherit 使元素继承父元素的盒模型模式 
d.此值主要目的是控制元素的总宽度

二、实践:

1.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css" >
        *{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            width: 960px;
            margin-left: auto;
            margin-right: auto;
            color:#6bb2ff;
            font-size: 30px;
            text-align: center;
        }
        #header{
            height: 100px;
            background: #228833;
            margin-bottom: 10px;
        }
        .sidebar{
            float:left;
            width: 220px;
            margin-right: 20px;
            margin-bottom: 10px;
            height: 300px;
            background: #ebf3fc;
        }
        .content{
            float:left;
            width: 720px;
            height: 300px;
            background: #ffcc99;
            margin-bottom: 10px;
        }
        #footer{
            background: #a6f821;
            height: 100px;
            clear: both;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div id="header">hedaer</div>
        <div class="sidebar">left</div>
        <div class="content">main</div>
        <div id="footer">footer</div>
    </div>
</body>
</html>
2.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css" >
        *{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            width: 960px;
            margin-left: auto;
            margin-right: auto;
            color:#6bb2ff;
            font-size: 30px;
            text-align: center;
            background: #ffcc99;
        }
        #header{
            height: 100px;
            background: #228833;
            margin-bottom: 10px;
            padding: 10px;
            width: 100%;
        }
        .sidebar{
            float:left;
            width: 220px;
            margin-right: 20px;
            margin-bottom: 10px;
            height: 300px;
            background: #ebf3fc;
            padding: 10px;
        }
        .content{
            float:left;
            width: 720px;
            height: 300px;
            background: #ffcc99;
            margin-bottom: 10px;
            padding: 10px;
        }
        #footer{
            background: #a6f821;
            height: 100px;
            clear: both;
            padding: 10px;
            width: 100%;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div id="header">hedaer</div>
        <div class="sidebar">left</div>
        <div class="content">main</div>
        <div id="footer">footer</div>
    </div>
</body>
</html>
3.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css" >
        *{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            width: 960px;
            margin-left: auto;
            margin-right: auto;
            color:#6bb2ff;
            font-size: 30px;
            text-align: center;
            background: #ffcc99;
        }
        #header{
            height: 100px;
            background: #228833;
            margin-bottom: 10px;
            padding: 10px;
            width: 100%;
            border: 10px solid darkgray;
        }
        .sidebar{
            float:left;
            width: 220px;
            margin-right: 20px;
            margin-bottom: 10px;
            height: 300px;
            background: #ebf3fc;
            padding: 10px;
            border: 10px solid red;
        }
        .content{
            float:left;
            width: 720px;
            height: 300px;
            background: #ffcc99;
            margin-bottom: 10px;
            padding: 10px;
            border: 10px solid chartreuse;
        }
        #footer{
            background: #a6f821;
            height: 100px;
            clear: both;
            padding: 10px;
            width: 100%;
            border: 10px solid #202189;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div id="header">hedaer</div>
        <div class="sidebar">left</div>
        <div class="content">main</div>
        <div id="footer">footer</div>
    </div>
</body>
</html>
4.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css" >
        *{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            width: 960px;
            margin-left: auto;
            margin-right: auto;
            color:#6bb2ff;
            font-size: 30px;
            text-align: center;
            background: #ffcc99;
        }
        #header{
            height: 100px;
            background: #228833;
            margin-bottom: 10px;
            padding: 10px;
            width: 100%;
            border: 10px solid darkgray;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing:border-box;
            -ma-box-sizing:border-box;
            box-sizing: border-box;
        }
        .sidebar{
            float:left;
            width: 220px;
            margin-right: 20px;
            margin-bottom: 10px;
            height: 300px;
            background: #ebf3fc;
            padding: 10px;
            border: 10px solid red;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing:border-box;
            -ma-box-sizing:border-box;
            box-sizing: border-box;
        }
        .content{
            float:left;
            width: 720px;
            height: 300px;
            background: #ffcc99;
            margin-bottom: 10px;
            padding: 10px;
            border: 10px solid chartreuse;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing:border-box;
            -ma-box-sizing:border-box;
            box-sizing: border-box;
        }
        #footer{
            background: #a6f821;
            height: 100px;
            clear: both;
            padding: 10px;
            width: 100%;
            border: 10px solid #202189;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing:border-box;
            -ma-box-sizing:border-box;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div id="header">hedaer</div>
        <div class="sidebar">left</div>
        <div class="content">main</div>
        <div id="footer">footer</div>
    </div>
</body>
</html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值