HTML基礎第二課(背景設置,外邊距,內邊距)

一、背景設置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>背景設置</title>
    <link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<!-- 背景樣式 background -->
<!-- 背景顏色 background-color:顏色值; -->
<!-- 背景圖片 background-image:url(“圖片路徑”) -->
<!-- 背景圖片平鋪background-repeat:repeat-x(沿着x平鋪)|repeat-y(沿着y平鋪)|no-repeat(都不平鋪);指定圖片的平鋪方式 -->
<!-- 背景圖片定位 backgroud-position:x,y; -->
<!-- x:支持left center right 支持百分比-->
<!-- y:支持top center bottom 支持百分比-->
<!-- 背景圖片尺寸 background-size:x y |cover(拉伸)|contain(-->

<!-- background:複合寫法 -->
<!-- background:background-color background-image background-position background-repeat -->
 <div>春眠不覺曉,處處聞啼鳥</div>

</body>
</html>
css:
div{
width: 1200px;
height: 800px;
border: 1px red solid;
/*background-color: yellow;
background-image: url("dm.jpg"),url("dm1.jpg");
background-repeat: no-repeat,repeat-y;
background-position: 0px 0px ;
background-size: 50% 50% ;*/
/*順序可以任意*/
/*size*/
/*多背景*/
background:   url("dm.jpg") 0px 0px/200px 200px no-repeat,url("dm1.jpg")  right/300px 300px repeat-y;


}

三、外邊距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外邊距</title>
    <link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<!-- 外邊距 margin -->
<!-- 左邊距 margin-left :數值|auto-->
<!-- 右邊距 margin-right:數值|auto-->
<!-- 上邊距 margin-top -->
<!-- 下邊距 margin-bottom -->

<!-- 外邊距複合寫法 -->
<!-- 1:margin:0px 0px 0px 0px (第一上 第二 右 第三 下 第四 左-->
<!-- 2:margin:0px 0px 0px(第一表示上,中間左右,第三表示下 -->
<!-- 3:margin:0px 0px(第一個是上下邊距,第二個是左右邊距) -->
<!-- 4:margin:0px(上下左右邊距都是這個值) -->
<div>
 <div class="div1">我是div1</div>
 <div class="div2">我是div2</div></div>
</body>
</html>

css:
div{
    width: 200px;
    height: 200px;
    background: red;
    border: 1px gold solid;
}
.div1{
    margin-left: 100px;
    margin-top: 100px;
    margin-bottom: 50px

}
.div2{
    background: blue;
    margin-left: 300px;
    margin-top: -200px;
}

三、外邊距坑

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外邊距的坑</title>
<style type="text/css">
    div{
     width: 200px;
     height: 200px;

    }
    .div1{
        background-color: red;
        margin-bottom: 50px;
        border: 1px #eef0f0 solid;
    }
    .div2{
        margin-top: 51px;
        background-color: blue;
        }
        .hezi{
            width: 400px;
            height: 200px;
            background-color: #eef0f0;
            padding: 50px;
            margin: 
        }
</style>
</head>
<body>
<!-- 坑1:同級結構下,外邊距衝突的情況下,誰的數值大,就採用誰的 -->
<!-- 坑2:父子結構下,父級與子級存在都設置上邊距的情況下,父級沒有設置border..,時,子級的外邊距會引出”塌陷“的問題。 -->

<!-- 盒模型:構成:容器尺寸+padding+border+margin -->

    <div class="div1">
        <div class="div2">
            <div class="hezi"></div>
        </div>
    </div>
</body>
</html>

四、內邊距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外邊距</title>
    <link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<!-- 內邊距 padding -->
<!-- 左內邊距 padding-left :數值|auto-->
<!-- 右內邊距 padding-right:數值|auto-->
<!-- 上內邊距 padding-top -->
<!-- 下內邊距 padding-bottom -->

<!-- 外邊距複合寫法 -->
<!-- padding:0px 0px 0px 0px (第一上 第二 右 第三 下 第四 左-->
<!-- 2:padding:0px 0px 0px(第一表示上,中間左右,第三表示下 -->
<!-- 3:padding:0px 0px(第一個是上下邊距,第二個是左右邊距) -->
<!-- 4:padding:0px(上下左右邊距都是這個值) -->

 <div >我是div1</div>

</body>
</html>

css:
div{
    height: 200px;
   background: red;
   padding-left: 50px;
   padding-top: 50px;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章