day53 文本属性和背景属性及盒子内外边距

上节课复习:
    1、基本选择器
        #id号-id选择器
        .类名- 类选择器
        标签名-标签选择器
        * -通配符选择器
    2、组合选择器
        选择器 选择器 -后代选择器
        选择器>选择器 -儿子选择器
        选择器+选择器 -兄弟选择器
        选择器~选择器 -毗邻兄弟选择器
    3、交集、并集选择器
        选择器选择器:input.inp1
        选择器,选择器:input,.inp1
    4、属性选择器
        [属性名]
        [属性名=] : [class="inp1"]
        [属性名^=]
        [属性名$=]
        [属性名*=]
        input[属性名*=]
    5、序列选择器
        p:first-child
        p:last-child
        :nth-child(n)

        p:first-of-type
        :last-of-type
        :nth-of-type(n)
    7、伪类选择器
        a:link
        a:hover
        a:visited
        a:active
        input:focus
    6、伪元素选择器
        div:before {
    
    
            content:"";
            color:red;
        }
        div:after {
    
    
            content:"";
            color:red;
        }

        p:first-letter {
    
    }
        <div>
            <h1></h1>
            <a href=""></a>
        </div>
今日内容:
    1、样式/属性设置
        字体样式
        文本样式
        背景
    2、盒子模型

    3、网页布局
        标准流
        浮动流
        定位流

1.字体属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        p {
     
     
            /*font-weight: 900;*/
            /*font-style: italic;*/
            /*font-size: 50px;*/
            /*font-family: "Microsoft YaHei UI Light";*/

            font: lighter italic 20px "Microsoft Himalaya";
            /*color: blue;*/
            /*color: rgb(182, 201, 231);*/
            /*color: rgba(182, 201, 231,0.3);*/
            /*color: #0000FF;*/
        }
    </style>
</head>
<body>
<p>一行白鹭上青天</p>
</body>
</html>

2.文本属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
     
     
            width: 200px;
            height: 200px;
            background-color: red;

            /*text-align: center;*/
            /*line-height: 200px;*/
            /*text-decoration: underline;*/
            /*text-decoration: overline;*/
            /*text-decoration: line-through;*/
            text-indent: 10px;
        }


    </style>
</head>
<body>
<div>
    你好啊阿斯
</div>
</body>
</html>

3.背景属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {
     
     
            width: 600px;
            height: 600px;
            background-color: red;
            background-image: url("bg.jpg");
            /*background-size: 600px 600px;*/
            background-size: 100px 100px;
            background-repeat: no-repeat;
            /*background-repeat: no-repeat;*/
            /*background-repeat: repeat-x;*/
            /*background-repeat: repeat-y;*/

            /*background-position: 水平方向 垂直方向的位置;*/
            /*background-position: right bottom;*/

            /*background-attachment: fixed;*/
        }
        .box2 {
     
     
            width: 200px;
            height: 200px;
            background-color: yellow;
        }
        .box2 img {
     
     
            width: 100px;
        }

        .box3 {
     
     
            width: 200px;
            height: 2000px;
            background-color: green;
        }

    </style>
</head>
<body>

<div class="box1">
    <p>123213123123123</p>
</div>

<div class="box2">
    <img src="timg.jpg" alt="">
        <p>123123123123123</p>
</div>

<div class="box3"></div>
</body>
</html>

4.练习

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        /*body {*/
        /*    background-image: url("img/bg2.jpg");*/
        /*}*/

        .box1 {
     
     
            width: 960px;
            height: 720px;
            background-image: url("img/bg1.jpg");游戏背景
            background-size: 960px 720px;
        }
        .box2 {
     
     
            width: 960px;
            height: 720px;
            background-image: url("img/ksyx.png");开始游戏
            background-repeat: no-repeat;
            background-position: center bottom;
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="box2"></div>
</div>
</body>
</html>

5.练习2

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>


        .header {
     
     
            width: 960px;
            height: 118px;
            background-image: url("img/dht.png");
            background-repeat: repeat-x;
        }

    </style>
</head>
<body>
<div class="header">
</div>
</body>
</html>

6.练习3

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {
     
     
            width: 86px;
            height: 28px;
            background-image: url("img/jlt.png");
            background-position: -425px -100px;
        }
    </style>
</head>
<body>
<div class="box1">
</div>
</body>
</html>

7.盒子模型

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*html {*/
        /*    height: 100%;*/
        /*}*/
        /*body {*/
        /*    height: 100%;*/
        /*}*/
        /*.box1 {*/
        /*    width: 100%;*/
        /*    height: 100%;*/
        /*    background-color: red;*/
        /*}*/
        .sp1 {
     
     
            width: 200px;
            height: 200px;
            background-color: red;
            /*display: inline-block;*/
            display: none;
            /*visibility: hidden;*/
        }
        .sp2 {
     
     
            width: 200px;
            height: 200px;
            background-color: green;
            display: inline-block;

        }

        p span {
     
     
            color: red;
        }
    </style>
</head>
<body>
<div class="box1"></div>
<span class="sp1">你好</span>
<span class="sp2">你好</span>

<p>你好<span>egon</span></p>
</body>
</html>

8.边框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {
     
     
            width: 200px;
            height: 200px;
            background: yellow;

            /*border: 1px dotted red;*/
            /*border-width: 1px 2px 3px 4px;*/
            /*border-style: solid dotted dashed double;*/
            /*border-color: red green blue black;*/
            border: 1px dotted red;
            /*border-radius: 20px;*/
            border-radius: 50%;

            text-align: center;
            line-height: 200px;
        }
    </style>
</head>
<body>
<div class="box1">1111</div>
</body>
</html>

9.内边距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
     
     
            padding: 0;
            margin: 0;
        }
        div {
     
     
            width: 150px;
            height: 150px;
        }

        .box1 {
     
     
            /*height: 100px;*/
            box-sizing: border-box;

            border: 1px solid red;
            padding-top: 50px;
        }
        .box2 {
     
     
            width: 100px;
            border: 1px solid green;
            padding-left: 50px;
        }
        .box3 {
     
     
            border: 1px solid blue;
            padding-right: 50px;
        }
        .box4 {
     
     
            border: 1px solid yellow;
            padding-bottom: 50px;
        }

        .box5 {
     
     
            /*width: 50px;*/
            /*height: 50px;*/
            box-sizing: border-box;
            border: 1px solid aqua;
            padding: 50px;
        }

        .boxx {
     
     
            width: 20px;
            height: 20px;
            background-color: red;
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="boxx"></div>
</div>
<hr>
<div class="box2">
    22222
</div>
<hr>
<div class="box3">
    333
</div>
<hr>
<div class="box4">
    4444
</div>
<hr>
<div class="box5">
    5555
</div>
</body>
</html>

10.外边距

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
     
     
            padding: 0;
            margin: 0;
        }
        div {
     
     
            width: 150px;
            height: 150px;
        }

        .box1 {
     
     
            border: 1px solid red;
            /*margin-top: 100px;*/
            /*margin-left: 100px;*/
            margin-bottom: 70px;

            padding-top: 30px;
            padding-left: 30px;
            box-sizing: border-box;
        }
        .box2 {
     
     
            border: 1px solid green;
            margin-top: 60px;
        }
        .box3 {
     
     
            border: 1px solid blue;
            display: inline-block;
            margin-right: 50px;
        }
        .box4 {
     
     
            border: 1px solid yellow;
            display: inline-block;
            margin-left: 50px;
        }

        .box5 {
     
     
            border: 1px solid grey;

        }

        .boxx {
     
     
            width: 20px;
            height: 20px;
            background-color: red;

            /*margin-top: 30px;*/
            /*margin-left: 30px;*/
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="boxx"></div>
</div>
<div class="box2">
    22222
</div>
<div class="box3">
    333
</div>
<div class="box4">
    4444
</div>
<div class="box5">
    5555
</div>
</body>
</html>

11.盒子居中与内容居中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {
     
     
            width: 200px;
            height: 600px;
            background-color: red;

            text-align: center;
            line-height: 25px;
            padding-top: 250px;
            padding-bottom: 250px;
            box-sizing: border-box;

            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="box1">
    你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊你好啊
</div>
</body>
</html>

12.防止文字溢出

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>欢迎界面</title>
    <style type="text/css">

        div {
     
     
            width: 200px;
            height: 200px;

            /*字母、数字溢出,可以用下列属性控制自动换行:允许在单词内换行。
            http://www.w3school.com.cn/cssref/pr_word-break.asp
            */
            word-break: break-all;
        }

        .box1 {
     
     
            background-color: red;


        }
        .box2 {
     
     
            background-color: green;
        }

        .box3 {
     
     
            background-color: blue;
        }
    </style>
</head>
<body>
<div class="box1">
    <p>asdfasdfsadfasdfasdfasdfad sfasdfsadasDSfafsafaasdfasdfasfdqwerqwerwqersdfqerwrsdf你好我的啊啊啊啊啊啊啊啊啊啊啊啊</p>

</div>


<div class="box2">遗憾白鹭上青天两个黄鹂鸣翠柳啊哈哈哈

</div>

<div class="box3">我是12312312312312312312312312312312312312312312312312312312312我
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/yinlingjishu/article/details/108698264