CSS盒子模型

可以把html頁面上每個標簽看做是一個盒子。
盒子相關(guān)的屬性:
寬度和高度(width和height): 決定這個盒子的容量
內(nèi)邊距(padding): 盒子邊框與內(nèi)容的距離
邊框(border): 盒子的厚度
外邊距(margin): 盒子與盒子之間的距離

屏幕快照 2017-02-06 上午10.40.31.png
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>盒子模型</title>
<style type="text/css">
    div{
        /*寬度和高度*/
        width:100px;
        height:100px;
        /*設(shè)置邊框*/
        border:3px solid #000;
        /*設(shè)置內(nèi)邊距*/
        /*左內(nèi)邊距*/
        padding-left:10px;
        /*上內(nèi)邊距*/
        padding-top:20px;
    }
    
    #div1{
        /*下外邊距*/
        /*margin-bottom:10px;*/
    }

    #div2{
        /*上外邊距*/
        margin-top:10px;
    }
</style>
</head>

<body>
<div id="div1">div1</div>
<div id="div2">div2</div>
</body>
</html>
屏幕快照 2017-02-06 上午10.40.59.png
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主頁面</title>

</head>
<frameset rows="10%,*,10%">
    <frame src="header.html" name="header"/>
        <frameset cols="20%,*">
            <frame src="menu.html"/>
            <frame src="main.html" name="main"/>
        </frameset>
    <frame src="footer.html"/>
</frameset>
<body>
<!--
    frameset 框架集
        屬性:
            cols: 按照列的方向來劃分框架
            rows: 按照行的方向來劃分框架
            以上兩個屬性的值填每個框架的比例或者長度
                *號表示其他框架分配完之后剩下的比例
                
    frame 表示一個框架,框架中包含一個html頁面
        有2個或2個以上的frame就會包含在frameset當中。

    注意:
        框架標簽不能放在body標簽中,否則無法顯示?。?!
 -->

</body>
</html>
屏幕快照 2017-02-06 上午10.40.48.png
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>css定位</title>
<style type="text/css">
    div{
        width:100px;
        height:100px;
        border:3px solid #000;
    }
    
    #div1{
        background-color:#F00;
    }
    
    #div2{
        background-color:#00F;
    }
    
    #div3{
        background-color:#0F0;
        /*相對定位*/
        /*
        position:relative;
        left:10px;
        top:10px;
        */
        
        /*絕對定位*/
        position:absolute;
        left:20px;
        top:20px;
    }
    
    #adv1{
        width:300px;
        height:300px;
        border:3px solid #00F;
        background-color:#09F;
        /*絕對定位*/
        /*position:absolute;*/
        /*固定定位*/
        position:fixed;
        left:450px;
        top:200px;
    }
</style>
</head>

<body>
<div id="div1">div1</div>
<div id="div2">div2</div>
<div id="div3">div3</div>
網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)
網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)
網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)容網(wǎng)站內(nèi)
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div id="adv1">立刻咨詢立刻咨詢立刻咨詢立刻咨詢立刻咨詢立刻咨詢立刻咨詢</div>
</body>
</html>
屏幕快照 2017-02-06 上午10.40.24.png
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模擬QQ登陸頁面</title>
<style type="text/css">
    /*修飾主div*/
    #main{
        /*寬度和高度*/
        width:450px;
        height:300px;
        /*邊框*/
        border:1px solid #000;
        /*設(shè)置外邊距*/
        /*簡寫屬性*/
        margin:150px 0 0 420px;
        
        /*設(shè)置背景圖片*/
        background-image:url(../05.%E7%B4%A0%E6%9D%90/1.jpg);
        background-repeat:no-repeat;
        background-position:top center;
    }
    
    /*用戶名div*/
    #userName{
        /*設(shè)置外邊距*/
        margin:60px 0 0 100px;
    }
    
    /*密碼div*/
    #userPwd{
        /*設(shè)置外邊距*/
        margin:20px 0 0 100px;
    }
    
    /*按鈕div*/
    #btn{
        /*設(shè)置外邊距*/
        margin:20px 0 0 150px;
    }
    
    /*注冊按鈕*/
    #regBtn{
        margin-left:30px;
    }
    
    /*設(shè)置用戶輸入框的背景*/
    #nameInput{
        background-image:url(../05.%E7%B4%A0%E6%9D%90/head.png);
        background-repeat:no-repeat;
        /*設(shè)置左內(nèi)邊距*/
        padding-left:30px;
    }
    
    /*設(shè)置密碼輸入框的背景*/
    #pwdInput{
        background-image:url(../05.%E7%B4%A0%E6%9D%90/key.jpg);
        background-repeat:no-repeat;
        /*設(shè)置左內(nèi)邊距*/
        padding-left:30px;
    }
</style>
</head>

<body>
<div id="main">
    <form>
        <div id="userName">
            用戶名:<input id="nameInput" type="text" name="userName"/>
        </div>
        <div id="userPwd">
            密&nbsp;&nbsp;碼:<input id="pwdInput" type="password" name="userPwd"/>
        </div>
        <div id="btn">
            <input type="submit" value="登陸"/><input type="button" value="立即注冊" id="regBtn"/>
        </div>
    </form>
</div>
</body>
</html>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 前言 總括: 對于盒子模型,BFC,IFC和外邊距合并等概念和問題的總結(jié) 原文地址:從CSS盒子模型說起 知乎專欄...
    秦至閱讀 858評論 0 3
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標簽默認的外補...
    _Yfling閱讀 14,189評論 1 92
  • 最近在工作中遇到很多樣式的問題,雖然是解決了但是總覺得自己知其然而不知其所以然。今天簡單的了解了盒子模型,解開了我...
    魏永_Owen_Wei閱讀 536評論 0 0
  • 小時候我經(jīng)常喜歡逗弄路邊的含羞草,一片片稚嫩的葉子排排并攏,一會兒,又徐徐地張開。小小的葉子,讓我想到了少女的臉龐...
    書未來閱讀 278評論 4 2
  • 今天師姐考博回來,帶大家去吃飯,分享了一次考博的經(jīng)驗。確實是收獲很多,雖說我不一定讀博,但多了解一些東西,接觸一些...
    喜歡吃土豆的土豆閱讀 167評論 0 0

友情鏈接更多精彩內(nèi)容