css-Basics

css基础

css

1css简介link rel href style

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        /* 
        第二种方式(内部样式表)

    -将样式编写到head中的style标签里
    然后通过css的选择器来选中元素并为其设置各种样式
    可以同时为多个标签设置样式,并且修改时只需要修改一处即可-内部样式表更加方便对样式进行复用 

        问题:
我们的内部样式表只能对一个网页起作用,
它里边的样式不能跨页面进行复用

*/
        p{
            color:green;
            font-size: 60px;
        }
    </style>

    <!-- 
     

    第三种方式(外部样式表)最佳实践

    -可以将css样式编写到一个外部的Css文件中,
    然后通过link标签来引入外部的Css文件-外部样式表需要通过link标签进行引入,
    意味着只要想使用这些样式的网页都可以对其进行引用使样式可以在不同页面之间进行复用

    将样式编写到外部的CSS文件中,可以使用到浏览器的缓存机制,
从而加快网页的加载速度,提高用户的体验。

-->
<link rel="stylesheet" href="style.css">
</head>
<body>
    <!-- 

        网页分成三个部分:
结构(HTML)表现(cSS)
行为(JavaScript)
Css
-层叠样式表
-网页实际上是一个多层的结构,通过css可以分别为网页的每一个层来设置样式
而最终我们能看到只是网页的最上边一层
-总之一句话,css用来设置网页中元素的样式 

-->
<!-- 
    使用css来修改元素的样式
    第一种方式(内联样式,行内样式);

    -在标签内部通过style属性来设置元素的样式-问题:

    使用内联样式,样式只能对一个标签生效,
    如果希望影响到多个元素必须在每一个元素中都复制一遍
    并且当样式发生变化时,我们必须要一个一个的修改,非常的不方便
    -注意:开发时绝对不要使用内联样式 
-->

<p style="color:red;font-size:60px">aasbbb</p>
</body>
</html>

2css语法

<!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>
      /*
        
        CSS中的注释,注释中的内容会自动被浏览器所忽略

        CSS的基本语法:
            选择器 声明块

            选择器,通过选择器可以选中页面中的指定元素
                比如 p 的作用就是选中页面中所有的p元素

            声明块,通过声明块来指定要为元素设置的样式
                声明块由一个一个的声明组成
                声明是一个名值对结构
                    一个样式名对应一个样式值,名和值之间以:连接,以;结尾   

      
      */

      p{
          color: red;
          font-size: 40px;
      }

      h1{
          color: green;
      }

      
    
    </style>
</head>
<body>
    <h1>我是H1</h1>
    <p>今天天气真不错!</p>
    <p>今天天气真不错!</p>
    <p>今天天气真不错!</p>
    <p>今天天气真不错!</p>
</body>
</html>

3常用选择器 id选择器 类选择器 通配选择器 class

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 

        元素选择器

        将所有的段落设置为红色(字体)元素选择器
作用:根据标签名来选中指定的元素语法:标签名行
例子:pl{} h1{} div{} 
*/
/* 
id选择器
作用:根据元素的id属性值选中一个元素语法:
格式:#id属性值
例子:#box{} #red{}
 */

 /* 
 类选择器
作用:根据元素的class属性值选中一组元素语法:.class属性值
 */

 #red{
     color:red;
 }

 .blue{
     color:blue;
 }

 .abc{
     font-size:100px;
 }
/* 
 通配选择器
作用:选中页面中的所有元素语法:* 
*/
*{
    color:green;
}





    </style>
</head>
<body>
    
    <p id="red">aaa</p>
    <p>bbb</p>

    <!-- 
        class是一个标签的属性,它和id类似,不同的是class可以重复使用
可以通过class属性来为元素分组 
-->

    <p class="blue abc">ccc</p>
    <p>ddd</p>
    <p>eee</p>
    
</body>
</html>

4复合选择器 交集选择器 选择器分组

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        /* 
交集选择器
作用:选中同时复合多个条件的元素语法:
    选择器1 选择器2 选择器3 选择器n{}
    注意点:
    交集选择器中如果有元素选择器,必须使用元素选择器开头 
*/

.red{
    color:red;
}

div.red{
    font-size: 200px;
}

.a.b.c{
    color:yellow;
}
/* 

选择器分组(并集选择器)
    作用:同时选择多个选择器对应的元素
    语法:选择器1,选择器2,选择器3,选择器n{} 
    #b1,p1,h1,span,div.red{}

*/
p,span{
    color:blue;   
}

    </style>
</head>
<body>


    <div class="red">woshi</div>
    <h1>aaa</h1>
    <p>aaa</p>
    
</body>
</html>

5关系选择器 子元素选择器 后代元素选择器 兄弟选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<style>
    /* 
    为div的子元素span设置一个字体颜色红色(为div直接包含的span设置一个字体颜色)

        子元素选择器作用:
        选中指定父元素的指定子元素语法:父元素>子元素 
*/

/* div > span{
    color: red;
} */

/* 复合写法 */
/* div>p>span{
    color:blue;
} */

/* 
后代元素选择器:
作用:
    选中指定元素内的指定后代元素语法:祖先 后代!!!!!!!!!!!!!!!!!!!!!!
     */
/* div span{
    color:green;
} */

/* 
选择下一个兄弟
语法:前一个+下一个 

选择下边所有的兄弟
语法:兄~弟

*/

/* p+span{
    color:rgb(255, 0, 0);
} */

p~span{
    color:red;
}
</style>

</head>
<body>

    <!-- 
父元素
    -直接包含子元素的元素叫做父元素
子元素
    -直接被父元素包含的元素是子元素
祖先元素
    -直接或间接包含后代元素的元素叫做祖先元素-一个元素的父元素也是它的祖先元素
后代元素
    -直接或间接被祖先元素包含的元素叫做后代元素-子元素也是后代元素
兄弟元素
    -拥有相同父元素的元素是兄弟元素 
-->

    
<div>
    <p>
        aaa
        <span>bbb</span>
    </p>
    <span>ccc</span>
    <span>ccc</span>
    <span>ccc</span>
    <span>ccc</span>
    <span>ccc</span>
</div>

</body>
</html>

6属性选择器= ^= $= *=

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

/* 
[属性名]选择含有指定属性的元素
[属性名=属性值]选择含有指定属性和属性值的元素
[属性名^=属性值]选择属性值以指定值开头的元素
[属性名$=属性值]选择属性值以指定值结尾的元素
[属性名*=属性值]选择属性值中含有某值的元素的元素 
*/

/* p[title]{ */
/* p[title=abc]{ */
/* p[title^=abc]{ */
/* p[title$=abc]{ */
p[title*=abc]{
    color:red;
}
    </style>
</head>
<body>
    <p title="abc">aaa</p>
    <p title="abcdef">bbb</p>
    <p title="helloabc">ccc</p>
    <p>ddd</p>
    <p>eee</p>
</body>
</html>

7伪类选择器 :nth-child() :nth-of-type()

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>    
    /* 
    伪类(不存在的类,特殊的类)
-伪类用来描述一个元素的特殊状态
比如:第一个子元素、被点击的元素、鼠标移入的元素...-伪类一般情况下都是使用:开头
        :first-child第一个子元素
        :last-child 最后一个子元素
        :nth-child()选中第n个子元素
    特殊值:
        n第n个 n的范围o到正无穷
        2n或even表示选中偶数位的元素
        2n+1 或odd表示选中奇数位的元素
        以上这些伪类都是根据所有的子元素进行排序


        :first-of-type
        :last-of-type
        :nth-of-type()
        -这几个伪类的功能和上述的类似,不通点是他们是在同类型元素中进行排序 

        :not()否定伪类
            -将符合条件的元素从选择器中去除

*/

/* ul > li:first-child{ */
    /* ul > li:last-child{ */
/* ul > li:nth-child(2){ */
/* ul > li:nth-child(2n){ */
/* ul > li:nth-child(odd){ */
    /* 以上这些伪类都是根据所有的子元素进行排序 */

/* ul > li:first-of-type{ */
    /* ul > li:first-of-type{
        color:red;  
} */
/* ul > li:nth-of-type(5){
    color:red;
} */
/* 这几个伪类的功能和上述的类似,不通点是他们是在同类型元素中进行排序  */

ul>li:nth-of-type(3){
    color:red;
}

</style>



</head>
<body>
    <ul>
        <span>000</span>
        <li>111</li>
        <li>222</li>
        <li>333</li>
        <li>444</li>
        <li>555</li>
    </ul>
</body>
</html>

8a元素的伪类 :link

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

/* 
只有a标签能用
:link用来表示没访问过的链接(正常的链接) 
*/
        a:link{
            color:blue;
        }

        /* 
        只有a标签能用
        :visited用来表示访问过的链接 
        由于隐私的原因,所以visited这个伪类只能修改链接的颜色

        */
        a:visited{
            color:red;
        }

        /* 
        :hover用来表示鼠标移入的状态 
        */
        a:hover{
            font-size:50px;
            color:green;
        }

        /* 
        :active用来表示鼠标点击 
        */
        a:active{
            font-size:100px;
            color:yellow;
        }


    </style>

</head>
<body>
    
    <a href="http://www.baidu.com">访问过得链接</a>
    <br><br>
    <a href="http://www.baidu123.com">没访问过得链接</a>

</body>
</html>

9伪元素选择器::first-letter ::first-line ::selection ::before ::after content

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

/* 
        伪元素,表示页面中一些特殊的并不真实的存在的元素(特殊的位置)
伪元素使用::开头
        ::first-letter表示第一个字母  优先级更高
        ::first-line 表示第一行l
        ::selection表示选中的内容 

        ::before元素的开始
        ::after元素的最后
        - before和 after必须结合content属性来使用


*/

p::first-letter{
    font-size:60px;
    color:green;
}

p::first-line{
    color:blue;
    /* font-size:100px; */
}

p::selection{
    color:red;
    /* font-size: 110px; 不能缩放字体 */
}

div::before{
    content: 'abc';
    color:red;
}

div::after{
    content:'abc';
    color:violet;
}

    </style>

</head>
<body>
    
    <div>Def sdkfjls   sdjfslkd  helloworld</div>

    <p>Bob Greene 1 In the house where I grew up, it was our custom to leave the front door on the latch at night。 I don t know if that was a local term or if it is universal; on the latch meant the door was closed but not locked。</p>
    <p>Bob Greene 1 In the house where I grew up, it was our custom to leave the front door on the latch at night。 I don t know if that was a local term or if it is universal; on the latch meant the door was closed but not locked。</p>

</body>
</html>

10继承

<!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>

        /* body{
            font-size: 12px;
        } */

        /* 
            样式的继承,我们为一个元素设置的样式同时也会应用到它的后代元素上

            继承是发生在祖先后后代之间的

            继承的设计是为了方便我们的开发,
                利用继承我们可以将一些通用的样式统一设置到共同的祖先元素上,
                    这样只需设置一次即可让所有的元素都具有该样式

            注意:并不是所有的样式都会被继承:
                比如 背景相关的,布局相关等的这些样式都不会被继承。
         */
        
        p{
            color: red;
            background-color: orange;
        }

        div{
            color: yellowgreen
        }
    
    </style>
</head>
<body>
    <p>
        我是一个p元素
        <span>我是p元素中的span</span>
    </p>

    <span>我是p元素外的span</span>

    <div>
        我是div
        <span>
            我是div中的span
            <em>我是span中的em</em>
        </span>
    </div>
</body>
</html>

11选择器的权重(优先级)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

/* 
样式的冲突
-当我们通过不同的选择器,选中相同的元素,并且为相同的样式设置不同的值时,此时就发生了样式的冲突。
发生样式冲突时,应用哪个样式由选择器的权重(优先级)决定
选择器的权重
内联样式        1,0,0,0
id选择器        0,1,0,0
类和伪类选择器   0,0,1,0
元素选择器      0,0,0,1
通配选择器      0,0,0,0
继承的样式      没有优先级

比较优先级时,需要将所有的选择器的优先级进行相加计算,最后优先级越高,则越优先显示(分组选择器是单独计算的),

选择器的累加不会超过其最大的数量级,类选择器在高也不会超过id选择器

如果优先级计算后相同,此时则优先使用靠下的样式工

可以在某一个样式的后边添加!important ,则此时该样式会获取到最高的优先级,甚至超过内联样式,
注意:在开发中这个玩意一定要慎用!
*/

.red{
    color:red;
}

.blue{
    color:blue;
}
    </style>



</head>
<body>
    
    <p class="blue red">aaa</p>


</body>
</html>

12单位 像素 百分比 em rem

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

<style>
    /* 
    长度单位:
像素
-屏幕〔显示器)实际上是由一个一个的小点点构成的
-不同屏幕的像素大小是不同的,像素越小的屏幕显示的效果越清晰
-所以同样的200px在不同的设备下显示效果不一样

百分比
-也可以将属性值设置为相对于其父元素属性的百分比I

-设置百分比可以使子元素跟随父元素的改变而改变 


长度单位:
        像素
-屏幕(显示器)实际上是由一个一个的小点点构成的
-不同屏幕的像素大小是不同的,像素越小的屏幕显示的效果越清晰-所以同样的200px在不同的设备下显示效果不一样

        百分比
-也可以将属性值设置为相对于其父元素属性的百分比-设置百分比可以使子元素跟随父元素的改变而改变

em
- em是相对于元素的字体大小来计算的- 1em = 1font-size
1font-size默认为16px

- em会根据字体大小的改变而改变

rem
- rem是相对于根元素的字体大小来计算

*/

.a1{
    font-size: 20px;
    width:10em;
    height:10em;
    background-color: red;
}

.a2{
    /* font-size: 456px;无关 */
    width:10rem;
    height:10rem;
    background-color: green;
}

html{
    font-size: 30px;
}

</style>

</head>
<body>
    <div class="a1"></div>
<br><br>
<div class="a2"></div>

</body>
</html>

13颜色 RGB值 RGBA(可以设置透明度) 十六进制的RGB HSL值HSLA值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 
    颜色单位:
在css中可以直接使用颜色名来设置各种颜色
比如:red、orange、yellow、blue、green .. - ---但是在css中直接使用颜色名是非常的不方便

RGB值:
- RGB通过三种颜色的不同浓度来调配出不同的颜色- R red, G green , B blue
-每一种颜色的范围在日 - 255(0% - 100%)之间-语法:RGB(红色,绿色,蓝色)

RGBA:
-就是在rgb的基础上增加了一个a表示不透明度
-需要四个值,前三个和rgb一样,第四个表示不透明度
1表示完全不透明o表示完全透明.5半透明

十六进制的RGB值:
-语法:#红色绿色蓝色-颜色浓度通过30-ff
-如果颜色两位两位重复可以进行简写
#aabbcc -->#abc 

HSL值HSLA值
    H色相(0 - 360)
    S饱和度,颜色的浓度0% -100%
    L亮度,颜色的亮度0%-100%

*/

</style>
<body>
    
</body>
</html>

盒子模型

文档流

<!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>
        .box1{
            width: 100px;
            background-color: yellow;
        }

        .box2{
            width: 100px;
            background-color: red;
        }

        span{
            background-color: #bfa;
        }
    </style>
</head>
<body>
    <!-- 
        文档流(normal flow)
            - 网页是一个多层的结构,一层摞着一层
            - 通过CSS可以分别为每一层来设置样式
            - 作为用户来讲只能看到最顶上一层
            - 这些层中,最底下的一层称为文档流,文档流是网页的基础
                我们所创建的元素默认都是在文档流中进行排列
            - 对于我们来元素主要有两个状态
                在文档流中
                不在文档流中(脱离文档流)

            - 元素在文档流中有什么特点:
                - 块元素
                    - 块元素会在页面中独占一行(自上向下垂直排列)
                    - 默认宽度是父元素的全部(会把父元素撑满)
                    - 默认高度是被内容撑开(子元素)

                - 行内元素
                    - 行内元素不会独占页面的一行,只占自身的大小
                    - 行内元素在页面中左向右水平排列,如果一行之中不能容纳下所有的行内元素
                        则元素会换到第二行继续自左向右排列(书写习惯一致)
                    - 行内元素的默认宽度和高度都是被内容撑开
                
     -->

     <div class="box1">我是div1</div>
     <div class="box2">我是div2</div>

     <span>我是span1</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
     <span>我是span2</span>
</body>
</html>

2盒模型width height background-color

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        
        .box{
            /* 
            内容区((content),元素中的所有的子元素和文本内容都在内容区中排列
                内容区的大小由width 和 height两个属性来设置
                    width设置内容区的宽度
                    height设置内容区的高度
                     */
            width: 100px;
            height:100px;
            background-color: red;

            /* 
            边框(border),边框属于盒子边缘,边框里边属于盒子内部,出了边框都是盒子的外部
                边框的大小会影响到整个盒子的大小
                要设置边框,需要至少设置三个样式;
                边框的宽度border-width
                边框的颜色 border-color边框的样式border-style
             */

            border-width:10px;
            border-color:green;
            border-style:solid;

        }

    </style>
</head>
<body>

    <!-- 
        盒模型、盒子模型、框模型(box model)
    - Css将页面中的所有元素都设置为了一个矩形的盒子
    -将元素设置为矩形的盒子后,对页面的布局就变成将不同的盒子摆放到不同的位置-每一个盒子都由一下几个部分组成:
    内容区(content)
    内边距(padding)
    边框( border)
    外边距(margin) 
-->

    
<div class="box"></div>

</body>
</html>

3盒子模型_边框border

<!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>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;

            /* 
                边框
                    边框的宽度 border-width
                    边框的颜色 border-color
                    边框的样式 border-style
             */

             /* 
             border-width: 10px; 
                默认值,一般都是 3个像素
                border-width可以用来指定四个方向的边框的宽度
                    值的情况
                        四个值:上 右 下 左
                        三个值:上 左右 下
                        两个值:上下 左右
                        一个值:上下左右
                    
                除了border-width还有一组 border-xxx-width
                    xxx可以是 top right bottom left
                    用来单独指定某一个边的宽度

                    
             */
             /* border-width: 10px; */
             /* border-top-width: 10px;
             border-left-width: 30px; */

            color: red;


             /* 
                border-color用来指定边框的颜色,同样可以分别指定四个边的边框
                    规则和border-width一样

                border-color也可以省略不写,如果省略了则自动使用color的颜色值
              */
             /* border-color: orange red yellow green;
             border-color: orange; */


            /* 
                border-style 指定边框的样式
                    solid 表示实线
                    dotted 点状虚线
                    dashed 虚线
                    double 双线

                    border-style的默认值是none 表示没有边框

             */
             /* border-style: solid dotted dashed double;
             border-style: solid; */

             /* border-width: 10px;
             border-color: orange;
             border-style: solid; */

             /* 
                border简写属性,通过该属性可以同时设置边框所有的相关样式,并且没有顺序要求

                除了border以外还有四个 border-xxx
                    border-top
                    border-right
                    border-bottom
                    border-left
              */
              /* border: solid 10px orange; */
              /* border-top: 10px solid red;
              border-left: 10px solid red;
              border-bottom: 10px solid red; */

              border: 10px red solid;
              border-right: none;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

4盒子模型_内边距padding

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        /* 
        
        内边距(padding)
-内容区和边框之间的距离是内边距
-一共有四个方向的内边距;
        padding-top
        padding-right
        padding-bottom
        padding-left

-内边距的设置会影响到盒子的大小
-背景颜色会延伸到内边距上

一共盒子的可见框的大小,由内容区内边距和边框共同决定,

所以在计算盒子大小时,需要将这三个区域加到一起计算 




*/

.box1{
    width:200px;
    height:200px;
    background-color: green;

    border:20px blue solid;

/* 
    padding内边距的简写属性,可以同时指定四个方向的内边距
规则和border-width一样 */

    padding: 20px;
}

.box2{
    width:100%;
    height:100%;
    background-color:red;
}


    </style>

</head>
<body>

    <div class="box1">
        <div class="box2"></div>
    </div>
    
    
</body>
</html>

5盒子模型_水平方向的布局margin-left+border-left+padding-left+width+padding-right+border-right+margin-right = 其父元素内容区的宽度

<!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>
        .outer{
            width: 800px;
            height: 200px;
            border: 10px red solid;
        }

        .inner{
            /* width: auto;  width的值默认就是auto*/
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin-right: auto;
            margin-left: auto;
            /* margin-left: 100px;
            margin-right: 400px */
            /* 
                元素的水平方向的布局:
                    元素在其父元素中水平方向的位置由以下几个属性共同决定“
                        margin-left
                        border-left
                        padding-left
                        width
                        padding-right
                        border-right
                        margin-right

                    一个元素在其父元素中,水平布局必须要满足以下的等式
margin-left+border-left+padding-left+width+padding-right+border-right+margin-right = 其父元素内容区的宽度 (必须满足)

                0 + 0 + 0 + 200 + 0 + 0 + 0 = 800
                0 + 0 + 0 + 200 + 0 + 0 + 600 = 800


                100 + 0 + 0 + 200 + 0 + 0 + 400 = 800
                100 + 0 + 0 + 200 + 0 + 0 + 500 = 800
                    - 以上等式必须满足,如果相加结果使等式不成立,则称为过度约束,则等式会自动调整
                        - 调整的情况:
                            - 如果这七个值中没有为 auto 的情况,则浏览器会自动调整margin-right值以使等式满足
                    - 这七个值中有三个值和设置为auto
                        width
                        margin-left
                        maring-right
                        - 如果某个值为auto,则会自动调整为auto的那个值以使等式成立
                            0 + 0 + 0 + auto + 0 + 0 + 0 = 800  auto = 800
                            0 + 0 + 0 + auto + 0 + 0 + 200 = 800  auto = 600
                            200 + 0 + 0 + auto + 0 + 0 + 200 = 800  auto = 400

                            auto + 0 + 0 + 200 + 0 + 0 + 200 = 800  auto = 400


                            auto + 0 + 0 + 200 + 0 + 0 + auto = 800  auto = 300

                        - 如果将一个宽度和一个外边距设置为auto,则宽度会调整到最大,设置为auto的外边距会自动为0
                        - 如果将三个值都设置为auto,则外边距都是0,宽度最大
                        - 如果将两个外边距设置为auto,宽度固定值,则会将外边距设置为相同的值
                            所以我们经常利用这个特点来使一个元素在其父元素中水平居中
                            示例:
                                width:xxxpx;
                                margin:0 auto;



             */
        }
    </style>
</head>
<body>

    <div class="outer">

        <div class="inner"></div>

    </div>
    
</body>
</html>

6盒子模型垂直方向的布局margin

<!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>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            border: 10px red solid;

            /* 
                外边距(margin)
                    - 外边距不会影响盒子可见框的大小
                    - 但是外边距会影响盒子的位置
                    - 一共有四个方向的外边距:
                        margin-top
                            - 上外边距,设置一个正值,元素会向下移动
                        margin-right
                            - 默认情况下设置margin-right不会产生任何效果
                        margin-bottom
                            - 下外边距,设置一个正值,其下边的元素会向下移动
                        margin-left
                            - 左外边距,设置一个正值,元素会向右移动

                        - margin也可以设置负值,如果是负值则元素会向相反的方向移动

                    - 元素在页面中是按照自左向右的顺序排列的,
                        所以默认情况下如果我们设置的左和上外边距则会移动元素自身
                        而设置下和右外边距会移动其他元素

                    - margin的简写属性
                        margin 可以同时设置四个方向的外边距 ,用法和padding一样

                    - margin会影响到盒子实际占用空间
             */

             /* margin-top: 100px;
             margin-left: 100px;
             margin-bottom: 100px; */

             /* margin-bottom: 100px; */
             /* margin-top: -100px; */
             /* margin-left: -100px; */
             /* margin-bottom: -100px; */

             /* margin-right: 0px; */

             margin: 100px;
        }

        .box2{
            width: 220px;
            height: 220px;
            background-color: yellow
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
</body>
</html>

7垂直方向的布局overflow

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>

        .box{
            height:600px;
            background-color:green;
        }

        /* 
        默认情况下父元素的高度被内容撑开 
        */


        .inner{
            width:100px;
            height:100px;
            margin-bottom: 100px;
            background-color:yellow;
        }

        /* 
        子元素是在父元素的内容区中排列的,
                    如果子元素的大小超过了父元素,则子元素会从父元素中溢出
                    使用 overflow 属性来设置父元素如何处理溢出的子元素

                    可选值:
                        visible,默认值 子元素会从父元素中溢出,在父元素外部的位置显示
                        hidden 溢出内容将会被裁剪不会显示
                        scroll 生成两个滚动条,通过滚动条来查看完整的内容
                        auto 根据需要生成滚动条 

                        
                        overflow-x: 
                        overflow-y:
                        */

        .a{
            width:500px;
            height:200px;
            background-color: yellowgreen;
            /* overflow-y:scroll; */
            overflow: auto;
        }
    </style>

</head>
<body>
    
<!-- <div class="box">
<div class="inner"></div>
<div class="inner"></div>
</div> -->

<div class="a">
    轻轻地,夜雨悄悄落在窗前,静静地,夜雨无声落在心田。那一帘冬夜之雨,刷新那又能怎样?福爹多次派媒人上门   
</div>
</body>
</html>

8外边距的折叠

<!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>
        .box1 , .box2{
            width: 200px;
            height: 200px;
            font-size: 100px;
        }

        /* 
            垂直外边距的重叠(折叠)
                - 相邻的垂直方向外边距会发生重叠现象
                - 兄弟元素
                    - 兄弟元素间的相邻垂直外边距会取两者之间的较大值(两者都是正值)
                    - 特殊情况:
                        如果相邻的外边距一正一负,则取两者的和
                        如果相邻的外边距都是负值,则取两者中绝对值较大的

                    - 兄弟元素之间的外边距的重叠,对于开发是有利的,所以我们不需要进行处理


                - 父子元素
                    - 父子元素间相邻外边距,子元素的会传递给父元素(上外边距)
                    - 父子外边距的折叠会影响到页面的布局,必须要进行处理
        
         */

        .box1{
            background-color: #bfa;

            /* 设置一个下外边距 */
            margin-bottom: 100px;
        }

        .box2{
            background-color: orange;

            /* 设置一个上外边距 */
            margin-top: 100px;
        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            /* padding-top: 100px; */
            /* border-top: 1px #bfa solid; */
        }

        .box4{
            width: 100px;
            height: 100px;
            background-color: orange;
            margin-top: 100px;
        }
    </style>
</head>
<body>

    <div class="box3">
        <div class="box4"></div>
    </div>

    <!-- <div class="box1"></div>
    <div class="box2"></div> -->
    
</body>
</html>

9行内元素的盒模型display visibility

<!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>
        .s1{
            background-color: yellow;

            /* 
                行内元素的盒模型
                    - 行内元素不支持设置宽度和高度
                    - 行内元素可以设置padding,但是垂直方向padding不会影响页面的布局
                    - 行内元素可以设置border,垂直方向的border不会影响页面的布局
                    - 行内元素可以设置margin,垂直方向的margin不会影响布局
             */
             /* width: 100px;
             height: 100px; */

             /* padding: 100px; */

             /* border: 100px solid red; */

             margin: 100px;
        }

        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        a{
            /* 
                display 用来设置元素显示的类型
                    可选值:
                        inline 将元素设置为行内元素
                        block 将元素设置为块元素
                        inline-block 将元素设置为行内块元素 
                                行内块,既可以设置宽度和高度又不会独占一行
                        table 将元素设置为一个表格
                        none 元素不在页面中显示

                visibility 用来设置元素的显示状态
                    可选值:
                        visible 默认值,元素在页面中正常显示
                        hidden 元素在页面中隐藏 不显示,但是依然占据页面的位置
             */
            display: block;

            visibility: hidden;

            width: 100px;
            height: 100px;
            background-color: orange;
        }
    </style>
</head>
<body>

    <a href="javascript:;">超链接</a>
    <a href="javascript:;">超链接</a>


    <span class="s1">我是span</span>
    <span class="s1">我是span</span>
    
    <div class="box1"></div>
</body>
</html>

10默认样式 reset.css normalize.css

<!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>
    <!-- <link rel="stylesheet" href="./css/reset.css"> -->
    <link rel="stylesheet" href="./css/reset.css">

    <!-- 
        重置样式表:专门用来对浏览器的样式进行重置的
            reset.css 直接去除了浏览器的默认样式
            normalize.css 对默认样式进行了统一

     -->
    <style>
        /* 
            默认样式:
                - 通常情况,浏览器都会为元素设置一些默认样式
                - 默认样式的存在会影响到页面的布局,
                    通常情况下编写网页时必须要去除浏览器的默认样式(PC端的页面)
         */

        /* body{
            margin: 0;
        }

        p{
            margin: 0;
        }

        ul{
            margin: 0;
            padding: 0;
            /* 去除项目符号 * /
            list-style:none; 
        } */

        /* *{
            margin: 0;
            padding: 0;
        } */


        .box1{
            width: 100px;
            height: 100px;
            border: 1px solid black;
        }
    </style>
</head>
<body>
    
<div class="box1"></div>

<p>我是一个段落</p>
<p>我是一个段落</p>
<p>我是一个段落</p>

<ul>
    <li>列表项1</li>
    <li>列表项2</li>
    <li>列表项3</li>
</ul>

</body>
</html>

11盒子尺寸box-sizing

<!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>
        .box1{
            width: 100px;
            height: 100px;
            background-color: #bfa;
            padding: 10px;
            border: 10px red solid;
            /* 
                默认情况下,盒子可见框的大小由内容区、内边距和边框共同决定

                    box-sizing 用来设置盒子尺寸的计算方式(设置width和height的作用)
                        可选值:
                            content-box 默认值,宽度和高度用来设置内容区的大小
                            border-box 宽度和高度用来设置整个盒子可见框的大小
                                width 和 height 指的是内容区 和 内边距 和 边框的总大小
             */
            
            box-sizing: border-box;
        }
    
    </style>
</head>
<body>

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

12轮廓阴影和圆角box-shadow outline border-radius

<!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>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;

            /* box-shadow 用来设置元素的阴影效果,阴影不会影响页面布局 
                第一个值 水平偏移量 设置阴影的水平位置 正值向右移动 负值向左移动
                第二个值 垂直偏移量 设置阴影的水平位置 正值向下移动 负值向上移动
                第三个值 阴影的模糊半径
                第四个值 阴影的颜色
            */

            box-shadow: 0px 0px 50px rgba(0, 0, 0, .3) ; 

/* 

            outline 用来设置元素的轮廓线,用法和border一模一样
                轮廓和边框不同的点,就是轮廓不会影响到可见框的大小    
 */
            
        }

        /* .box1:hover{
            outline: 10px red solid;
        } */

        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;

            /* border-radius: 用来设置圆角 圆角设置的圆的半径大小*/

            /* border-top-left-radius:  */
            /* border-top-right-radius */
            /* border-bottom-left-radius:  */
            /* border-bottom-right-radius:  */
            /* border-top-left-radius:50px 100px; */

            /* 
                border-radius 可以分别指定四个角的圆角
                    四个值 左上 右上 右下 左下
                    三个值 左上 右上/左下 右下 
                    两个个值 左上/右下 右上/左下  
              */
            /* border-radius: 20px / 40px; */

            /* 将元素设置为一个圆形 */
            border-radius:50%;
        }
    </style>
</head>
<body>

    <!-- <div class="box1"></div> -->

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

浮动float

1浮动的简介

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

<style>
    /* 
                通过浮动可以使一个元素向其父元素的左侧或右侧移动
                    使用 float 属性来设置于元素的浮动
                        可选值:
                            none 默认值 ,元素不浮动
                            left 元素向左浮动
                            right 元素向右浮动

                    注意,元素设置浮动以后,水平布局的等式便不需要强制成立
                        元素设置浮动以后,会完全从文档流中脱离,不再占用文档流的位置,
                            所以元素下边的还在文档流中的元素会自动向上移动

                    浮动的特点:
                        1、浮动元素会完全脱离文档流,不再占据文档流中的位置
                        2、设置浮动以后元素会向父元素的左侧或右侧移动,
                        3、浮动元素默认不会从父元素中移出
                        4、浮动元素向左或向右移动时,不会超过它前边的其他浮动元素
                        5、如果浮动元素的上边是一个没有浮动的块元素,则浮动元素无法上移
                        6、浮动元素不会超过它上边的浮动的兄弟元素,最多最多就是和它一样高

                    简单总结:
                        浮动目前来讲它的主要作用就是让页面中的元素可以水平排列,
                            通过浮动可以制作一些水平方向的布局    
             */

             .box1{
                 width:400px;
                 height:200px;
                 background-color:green;

                 float:left;
             }

             .box2{
                 width:200px;
                 height:200px;
                 background-color:yellow;
                 float:right;
             }
             .box3{
                 width:400px;
                 height:200px;
                 background-color:blue;
                 float:left;
             }
</style>

</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box3"></div>
</body>
</html>

2浮动的其他特点

<!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;
        }

        .box1{
            width: 100px;
            height: 100px;
            background-color: #bfa;
            /* 
                浮动元素不会盖住文字,文字会自动环绕在浮动元素的周围,
                    所以我们可以利用浮动来设置文字环绕图片的效果
             */
            float: left;
        }

        .box2{
            background-color: yellowgreen;

            /*
                元素设置浮动以后,将会从文档流中脱离,从文档流中脱离后,元素的一些特点也会发生变化

                脱离文档流的特点:
                    块元素:
                        1、块元素不在独占页面的一行
                        2、脱离文档流以后,块元素的宽度和高度默认都被内容撑开

                    行内元素:
                        行内元素脱离文档流以后会变成块元素,特点和块元素一样

                    脱离文档流以后,不需要再区分块和行内了
              */



            float: left;
        }

        .box3{
            background-color: orange
        }

        .s1{
            float: left;
            width: 200px;
            height: 200px;
            background-color: yellow;
        }
    </style>
</head>
<body>


    <!-- <div class="box1"></div>
    <p>
       似的,只有半粒小麦那么大,遍身的颜色苍翠得可爱,可怜。 我打一个呵欠,点起一支纸烟,喷出烟来,对着灯默默地敬奠这些苍翠精致的英雄们。 一九二四年九月十五日。
    </p> -->


    <span class="s1">我是一个span</span>
    <!-- <div class="box2">helloaaaaa</div> -->
    <!-- <div class="box3">hello</div> -->

    
</body>
</html>

3简单的布局

<!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>

        header, main, footer{
            width: 1000px;
            margin: 0 auto;
        }

        /* 设置头部 */
        header{
            height: 150px;
            background-color: silver;
        }

        /* 设置主体 */
        main{
            height: 500px;
            background-color: #bfa;
            margin: 10px auto;
        }

        nav, article, aside{
            float: left;
            height: 100%;
        }

        /* 设置左侧的导航 */
        nav{
            width: 200px;
            background-color: yellow;
        }

        /* 设置中间的内容 */
        article{
            width: 580px;
            background-color: orange;
            margin: 0 10px;
        }

        /* 设置右侧的内容 */
        aside{
            width: 200px;
            background-color: pink;
        }

        /* 设置底部 */
        footer{
            height: 150px;
            background-color: tomato;
        }
    </style>
</head>
<body>

    <!-- 创建头部 -->
    <header></header>

    <!-- 创建网页的主体 -->
    <main>
        <!-- 左侧导航 -->
       <nav></nav>

       <!-- 中间的内容 -->
       <article></article>

       <!-- 右边的边栏 -->
       <aside></aside>

    </main>
    
    <!-- 网页的底部 -->
    <footer></footer>
</body>
</html>

4高度塌陷的问题BFC

<!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>
        .outer{
            border: 10px red solid;

            /* 
                BFC(Block Formatting Context) 块级格式化环境
                    - BFC是一个CSS中的一个隐含的属性,可以为一个元素开启BFC
                        开启BFC该元素会变成一个独立的布局区域
                    - 元素开启BFC后的特点:
                        1.开启BFC的元素不会被浮动元素所覆盖
                        2.开启BFC的元素子元素和父元素外边距不会重叠
                        3.开启BFC的元素可以包含浮动的子元素

                    - 可以通过一些特殊方式来开启元素的BFC:
                        1、设置元素的浮动(不推荐)
                        2、将元素设置为行内块元素(不推荐)
                        3、将元素的overflow设置为一个非visible的值
                            - 常用的方式 为元素设置 overflow:hidden 开启其BFC 以使其可以包含浮动元素
            
             */

             /* float: left; */
             /* display: inline-block; */
             overflow: hidden;
        }

        .inner{
            width: 100px;
            height: 100px;
            background-color: #bfa;

            /* 
                高度塌陷的问题:
                    在浮动布局中,父元素的高度默认是被子元素撑开的,
                        当子元素浮动后,其会完全脱离文档流,子元素从文档流中脱离
                        将会无法撑起父元素的高度,导致父元素的高度丢失

                    父元素高度丢失以后,其下的元素会自动上移,导致页面的布局混乱

                    所以高度塌陷是浮动布局中比较常见的一个问题,这个问题我们必须要进行处理!
             */
            float: left;
        }
    </style>
</head>
<body>

    <div class="outer">

        <div class="inner"></div>

    </div>

    <div style="width: 200px;height: 200px;background-color:yellow;"></div>
    
</body>
</html>

5BFC

<!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>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            /* float: left; */
            overflow: hidden;
        }

        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;
            overflow: hidden;
        }

        .box3{
            width: 100px;
            height: 100px;
            background-color: yellow;
            margin-top: 100px;
        }
    </style>
</head>
<body>

    <div class="box1">

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

    <!-- <div class="box2">

    </div> -->
    
</body>
</html>

6clear

<!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>

        div{
            font-size: 50px;
        }

        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            float: left;
        }

        .box2{
            width: 400px;
            height: 150px;
            background-color: #ff0;
            float: right;
        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: orange;
            /* 
                由于box1的浮动,导致box3位置上移
                    也就是box3收到了box1浮动的影响,位置发生了改变

                如果我们不希望某个元素因为其他元素浮动的影响而改变位置,
                    可以通过clear属性来清除浮动元素对当前元素所产生的影响

                clear
                    - 作用:清除浮动元素对当前元素所产生的影响
                    - 可选值:
                        left 清除左侧浮动元素对当前元素的影响
                        right 清除右侧浮动元素对当前元素的影响
                        both 清除两侧中最大影响的那侧

                    原理:
                        设置清除浮动以后,浏览器会自动为元素添加一个上外边距,
                            以使其位置不受其他元素的影响
             */

             clear: both;
        }
    </style>
</head>
<body>

    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div> 
    
</body>
</html>

07.高度塌陷的最终解决方案

<!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>
        .box1{
            border: 10px red solid;

            /* overflow: hidden; */
        }

        .box2{
            width: 100px;
            height: 100px;
            background-color: #bfa;
            float: left;
        }

        .box3{
            clear: both;
        }

        .box1::after{
            content: '';
            display: block;
            clear: both;
        }
        
    </style>
</head>
<body>

    <div class="box1">
        <div class="box2"></div>
        <!-- <div class="box3"></div> -->
    </div>
    
</body>
</html>

08.clearfix

<!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>
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        /* .box1::before{
            content: '';
            display: table;
        } */

        .box2{
            width: 100px;
            height: 100px;
            background-color: orange;
            margin-top: 100px;
        }

/* clearfix 这个样式可以同时解决高度塌陷和外边距重叠的问题,当你在遇到这些问题时,直接使用clearfix这个类即可 */
        .clearfix::before,
        .clearfix::after{
            content: '';
            display: table;
            clear: both;
        }
    </style>
</head>
<body>

    <div class="box1 clearfix">
        <div class="box2"></div>
    </div>
    
</body>
</html>

position

01.定位的简介 相对定位relative

<!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>
        body{
            font-size: 60px;
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;

            /*
                定位(position)
                    - 定位是一种更加高级的布局手段
                    - 通过定位可以将元素摆放到页面的任意位置
                    - 使用position属性来设置定位
                        可选值:
                            static 默认值,元素是静止的没有开启定位
                            relative 开启元素的相对定位
                            absolute 开启元素的绝对定位
                            fixed 开启元素的固定定位
                            sticky 开启元素的粘滞定位

                    - 相对定位:
                        - 当元素的position属性值设置为relative时则开启了元素的相对定位
                        - 相对定位的特点:
                            1.元素开启相对定位以后,如果不设置偏移量元素不会发生任何的变化
                            2.相对定位是参照于元素在文档流中的位置进行定位的
                            3.相对定位会提升元素的层级
                            4.相对定位不会使元素脱离文档流
                            5.相对定位不会改变元素的性质块还是块,行内还是行内

                    - 偏移量(offset)
                        - 当元素开启了定位以后,可以通过偏移量来设置元素的位置
                            top
                                - 定位元素和定位位置上边的距离
                            bottom
                                - 定位元素和定位位置下边的距离

                                - 定位元素垂直方向的位置由top和bottom两个属性来控制
                                    通常情况下我们只会使用其中一
                                - top值越大,定位元素越向下移动
                                - bottom值越大,定位元素越向上移动
                            left
                                - 定位元素和定位位置的左侧距离
                            right
                                - 定位元素和定位位置的右侧距离

                                - 定位元素水平方向的位置由left和right两个属性控制
                                    通常情况下只会使用一个
                                - left越大元素越靠右
                                - right越大元素越靠左

              */
            
            position: relative;

            left: 100px;
            top: -200px;

        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: yellow;

        }
    </style>
</head>
<body>

    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3</div>
    
</body>
</html>

02.绝对定位absolute

<!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>
        body{
            font-size: 60px;
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;

           /* 
            绝对定位
                - 当元素的position属性值设置为absolute时,则开启了元素的绝对定位
                - 绝对定位的特点:
                    1.开启绝对定位后,如果不设置偏移量元素的位置不会发生变化
                    2.开启绝对定位后,元素会从文档流中脱离
                    3.绝对定位会改变元素的性质,行内变成块,块的宽高被内容撑开
                    4.绝对定位会使元素提升一个层级
                    5.绝对定位元素是相对于其包含块进行定位的

                    包含块( containing block )
                        - 正常情况下:
                            包含块就是离当前元素最近的祖先块元素
                            <div> <div></div> </div>
                            <div><span><em>hello</em></span></div>

                        - 绝对定位的包含块:
                            包含块就是离它最近的开启了定位的祖先元素,
                                如果所有的祖先元素都没有开启定位则根元素就是它的包含块

                        - html(根元素、初始包含块)

            */

            position: absolute;
            /* left: 0;
            top: 0; */
            bottom: 0;
            right: 0;
        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: yellow;

        }

        .box4{
            width: 400px;
            height: 400px;
            background-color: tomato;
            position: relative;
        }
        
        .box5{
            width: 300px;
            height: 300px;
            background-color: aliceblue;
            /* position: relative; */
        }
    </style>
</head>
<body>

    <div class="box1">1</div>

    <div class="box4">
        4
        <div class="box5">
            5
            <div class="box2">2</div>
        </div>
    </div>
    <div class="box3">3</div>
    
</body> 
</html>

03固定定位fixed

<!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>
        body{
            font-size: 60px;
            height: 2000px;
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
        }

        .box2{
            width: 200px;
            height: 200px;
            background-color: orange;
            /*
                固定定位:
                    - 将元素的position属性设置为fixed则开启了元素的固定定位
                    - 固定定位也是一种绝对定位,所以固定定位的大部分特点都和绝对定位一样
                        唯一不同的是固定定位永远参照于浏览器的视口进行定位
                        固定定位的元素不会随网页的滚动条滚动

              */

            position: fixed;

            left: 0;
            top: 0;



        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: yellow;

        }

        .box4{
            width: 400px;
            height: 400px;
            background-color: tomato;

        }
        
        .box5{
            width: 300px;
            height: 300px;
            background-color: aliceblue;
        }
    </style>
</head>
<body>

    <div class="box1">1</div>

    <div class="box4">
        4
        <div class="box5">
            5
            <div class="box2">2</div>

        </div>
    </div>

    <div class="box3">3</div>

    
</body>
</html>

04粘滞定位sticky

<!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>导航条</title>
    <link rel="stylesheet" href="../去除默认格式/reset.css">
    <style>

        body{
            height: 3000px;
        }
        
        /* 设置nav的大小 */
        .nav{

            /* 设置宽度和高度 */
            width: 1210px;
            height: 48px;
            /* 设置背景颜色 */
            background-color: #E8E7E3;

            margin:100px auto;

            /* 
                粘滞定位
                    - 当元素的position属性设置为sticky时则开启了元素的粘滞定位
                    - 粘滞定位和相对定位的特点基本一致,
                        不同的是粘滞定位可以在元素到达某个位置时将其固定
             */

             position: sticky;
             top: 500px;

        }

        /* 设置nav中li */
        .nav li{
            /* 设置li向左浮动,已使菜单横向排列 */
            float: left;
            /* 设置li的高度 */
            /* height: 48px; */
            /* 将文字在父元素中垂直居中 */
            line-height: 48px;

        }

        /* 设置a的样式 */
        .nav a{
            /* 将a转换为块元素 */
            display: block;
            /* 去除下划线 */
            text-decoration: none;
            /* 设置字体颜色 */
            color: #777777;
            /* 修改字体大小 */
            font-size: 18px;

            padding: 0 39px;
        }

        .nav li:last-child a{
            padding: 0 42px 0 41px;
        }

        /* 设置鼠标移入的效果 */
        .nav a:hover{
            background-color: #3F3F3F;
            color: #E8E7E3;
        }
    </style>
</head>

<body>
    <!-- 创建导航条的结构 -->
    <ul class="nav">
        <li>
            <a href="#">HTML/CSS</a>
        </li>
        <li>
            <a href="#">Browser Side</a>
        </li>
        <li>
            <a href="#">Server Side</a>
        </li>
        <li>
            <a href="#">Programming</a>
        </li>
        <li>
            <a href="#">XML</a>
        </li>
        <li>
            <a href="#">Web Building</a>
        </li>
        <li>
            <a href="#">Reference</a>
        </li>
    </ul>

</body>

</html>

05绝对定位元素的布局 ,水平布局left + margin-left + border-left + padding-left + width + padding-right + border- right + margin-right + right = 包含块的内容区的宽度 ,垂直方向布局的等式的也必须要满足 top + margin-top/bottom + padding-top/bottom + border-top/bottom + height = 包含块的高度

<!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>

body{
        height:1000px;  
    }

        .box1{
             width: 500px;
            height: 500px;
        
            background-color: #bfa;
            /* margin:auto; */
            /* position: relative;  */

            
           
            
             
            /* background-color: orange; */
            position: absolute;
            margin: auto;
            left: 0;
             right: 0;

             top: 0;
             bottom: 0;
            
        }

        .box2{
            width: 100px;
            height: 100px;
            background-color: orange;
            position: absolute;
            margin: auto;
            /* 
                水平布局
                    left + margin-left + border-left + padding-left + width + padding-right + border-   right + margin-right + right = 包含块的内容区的宽度

                - 当我们开启了绝对定位后:
                    水平方向的布局等式就需要添加left 和 right 两个值
                        此时规则和之前一样只是多添加了两个值:
                            当发生过度约束:
                                如果9个值中没有 auto 则自动调整right值以使等式满足
                                如果有auto,则自动调整auto的值以使等式满足

                        - 可设置auto的值
                            margin width left right

                        - 因为left 和 right的值默认是auto,所以如果不指定left和right
                            则等式不满足时,会自动调整这两个值

                    垂直方向布局的等式的也必须要满足
                        top + margin-top/bottom + padding-top/bottom + border-top/bottom + height = 包含块的高度

            
             */

             left: 0;
             right: 0;

             top: 0;
             bottom: 0;
        }
    </style>
</head>
<body>

<div class="box1">
    <div class="box2"></div>
</div>
    
</body>
</html>

05元素的层级

<!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>
        body{
            font-size: 60px;
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            position: absolute;
            /* 
                对于开启了定位元素,可以通过z-index属性来指定元素的层级
                    z-index需要一个整数作为参数,值越大元素的层级越高
                        元素的层级越高越优先显示

                    如果元素的层级一样,则优先显示靠下的元素

                    祖先的元素的层级再高也不会盖住后代元素
             */
             /* z-index: 3; */
        }

        .box2{
            width: 200px;
            height: 200px;
            background-color: rgba(255 , 0, 0, .3);
            position: absolute;
            top: 50px;
            left: 50px;
            /* z-index: 3; */

        }

        .box3{
            width: 200px;
            height: 200px;
            background-color: yellow;
            position: absolute;
            top: 100px;
            left: 100px;
            z-index: 3;

        }

        .box4{
            width: 100px;
            height: 100px;
            background-color: orange;
            position: absolute;
        }
    </style>
</head>
<body>

    <div class="box1">1</div>
    <div class="box2">2</div>
    <div class="box3">3
        <div class="box4">4</div>
    </div>

    
</body>
</html>

font&background

01字体 font color

<!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>

        /* 
        font-face可以将服务器中的字体直接提供给用户去使用 
            问题:
                1.加载速度
                2.版权
                3.字体格式
        
        */
        @font-face {
                /* 指定字体的名字 */
            font-family:'myfont' ;
            /* 服务器中字体的路径 */
            src: url('./font/ZCOOLKuaiLe-Regular.ttf') format("truetype");
        }

        p{
            /* 
            字体相关的样式 
                color 用来设置字体颜色
                font-size 字体的大小
                    和font-size相关的单位
                    em 相当于当前元素的一个font-size
                    rem 相对于根元素的一个font-size
                font-family 字体族(字体的格式)
                    可选值:
                        serif  衬线字体
                        sans-serif 非衬线字体
                        monospace 等宽字体
                            - 指定字体的类别,浏览器会自动使用该类别下的字体

                    - font-family 可以同时指定多个字体,多个字体间使用,隔开
                        字体生效时优先使用第一个,第一个无法使用则使用第二个 以此类推

                        Microsoft YaHei,Heiti SC,tahoma,arial,Hiragino Sans GB,"\5B8B\4F53",sans-serif


            */
            color: blue;
            font-size: 40px;

            /* font-family: 'Courier New', Courier, monospace; */
            font-family: myfont;
        }
    </style>
</head>
<body>
    <p>
        今天天气真不错,Hello Hello How are you!
    </p>
</body>
</html>

02图标字体

<!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>
    <link rel="stylesheet" href="./fa/css/all.css">
</head>
<body>
    <!-- 
        图标字体(iconfont)
            - 在网页中经常需要使用一些图标,可以通过图片来引入图标
                但是图片大小本身比较大,并且非常的不灵活
            - 所以在使用图标时,我们还可以将图标直接设置为字体,
                然后通过font-face的形式来对字体进行引入
            - 这样我们就可以通过使用字体的形式来使用图标

        fontawesome 使用步骤
            1.下载 https://fontawesome.com/
            2.解压
            3.将css和webfonts移动到项目中
            4.将all.css引入到网页中
            5.使用图标字体
                - 直接通过类名来使用图标字体
                    class="fas fa-bell"
                    class="fab fa-accessible-icon"

     -->
    <i class="fas fa-bell" style="font-size:80px; color:red;"></i>
    <i class="fas fa-bell-slash"></i>
    <i class="fab fa-accessible-icon"></i>
    <i class="fas fa-hand-holding-heart" style="font-size: 160px; color:rgb(250, 65, 210);"></i>
</body>
</html>

03.图标字体

<!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>
    <link rel="stylesheet" href="./fa/css/all.css">
    <style>
        li{
            list-style: none;
        }

        li::before{
            /* 
                通过伪元素来设置图标字体
                    1.找到要设置图标的元素通过before或after选中
                    2.在content中设置字体的编码
                    3.设置字体的样式
                        fab
                        font-family: 'Font Awesome 5 Brands';

                        fas
                        font-family: 'Font Awesome 5 Free';
                        font-weight: 900; 

            */
            content: '\f1b0';
            /* font-family: 'Font Awesome 5 Brands'; */
            font-family: 'Font Awesome 5 Free';
            font-weight: 900; 
            color: blue;
            margin-right: 10px;

            font-size:100px;
        }
    </style>
</head>
<body>

    <!-- <i class="fas fa-cat"></i> -->

    <ul>
        <li style="font-size: 100px;">锄禾日当午</li>
        <li style="font-size: 100px;">汗滴禾下土</li>
        <li style="font-size: 100px;">谁知盘中餐</li>
        <li style="font-size: 100px;">粒粒皆辛苦</li>
    </ul>

    <!-- 

        通过实体来使用图标字体:
            &#x图标的编码;
     -->
    <span class="fas">&#xf0f3;</span>
    
</body>
</html>

04.阿里的字体库

<!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>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    <style>
        i.iconfont{
            font-size: 100px;
        }

        p::before{
            content: '\e8b1';
            font-family: 'iconfont';
            font-size: 100px;
        }
    </style>
</head>
<body>

    <i class="iconfont">&#xe8b3;</i>

    <p>Hello</p>
</body>
</html>

05.行高line-height

<!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>
        div{
            font-size: 50px;

            /* 可以将行高设置为和高度一样的值,使单行文字在一个元素中垂直居中 */
            line-height: 200px;

            /* 
                行高(line height)
                    - 行高指的是文字占有的实际高度
                    - 可以通过line-height来设置行高
                        行高可以直接指定一个大小(px em)
                        也可以直接为行高设置一个整数
                            如果是一个整数的话,行高将会是字体的指定的倍数
                    - 行高经常还用来设置文字的行间距
                        行间距 = 行高 - 字体大小

                字体框
                    - 字体框就是字体存在的格子,设置font-size实际上就是在设置字体框的高度

                行高会在字体框的上下平均分配

            */

            border: 1px red solid;

            /* line-height: 1.33; */
            /* line-height: 1; */
            /* line-height: 10 */
        }
    </style>
</head>
<body>
    
    <div>今天天气这不错 Hello hello 今天天气这不错 Hello hello 今天天气这不错 Hello hello 今天天气这不错 Hello hello</div>

</body>
</html>

06.字体的简写属性font

<!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>
        div{
            border: 1px red solid;


            /* 
                font 可以设置字体相关的所有属性
                    语法:
                        font: 字体大小/行高 字体族
                        行高 可以省略不写 如果不写使用默认值
            
            */

            /* font-size: 50px;
            font-family: 'Times New Roman', Times, serif; */
            font-weight: bold;
            /* font: 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            /* font: normal normal 50px/2  微软雅黑, 'Times New Roman', Times, serif; */
            font: bold italic 50px/2  微软雅黑, 'Times New Roman', Times, serif;
            /* font:50px 'Times New Roman', Times, serif;
            line-height: 2; */

            /* font-size: 50px; */

            /* font-weight 字重 字体的加粗 
                可选值:
                    normal 默认值 不加粗
                    bold 加粗
                    100-900 九个级别(没什么用)

                font-style 字体的风格
                    normal 正常的
                    italic 斜体
            */
            /* font-weight: bold; */
            /* font-weight: 500;
            font-style: italic; */



        }
    </style>
</head>
<body>
    
    <div>今天天气真不错 Hello hello</div>
    
</body>
</html>

07文本的样式text-align vertical-align

<!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>
        div{
            width: 800px;
            border: 1px red solid;

            /* 
                text-align 文本的水平对齐
                    可选值:
                        left 左侧对齐
                        right 右对齐
                        center 居中对齐
                        justify 两端对齐
            */
            /* text-align: justify; 或*/

            font-size: 50px;
        }

        span{
            font-size: 20px;
            border: 1px blue solid;

                /*
                vertical-align 设置元素垂直对齐的方式
                    可选值:
                        baseline 默认值 基线对齐
                        top 顶部对齐
                        bottom 底部对齐
                        middle 居中对齐
                */
            vertical-align:baseline; 
        }

        p{
            border: 1px red solid;

        }
        /* 保证图片不和基线对齐 */
        img{
            vertical-align: bottom;
        }

        .a{
            float: left;
        }
    </style>
</head>
<body>
    
<div>
    今天天气 Helloyx<span>真不错 Hello</span>
</div>

    <!-- <div>
        Lorem ipsum dolor, sit amet consectetur adipisicing elit. Illo nihil iure at ab atque nostrum molestiae totam porro, dolorem maiores repudiandae molestias veritatis, eligendi laudantium incidunt dolores corporis? Quibusdam, consequatur.
    </div> -->


    <p class="a">
       <img src="./photo/bb.jpg" alt="" height="563"> 
    </p>
    <p class="a">
       <img src="./photo/aa.webp" width="1000px"> 
    </p>

</body>
</html>

08文本样式text-decoration white-space

<!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>
        .box1{
            font-size: 50px;
            font-family: 微软雅黑;


            /* 
                text-decoration 设置文本修饰
                    可选值:
                        none 什么都没有
                        underline 下划线
                        line-through 删除线
                        overline 上划线
            */

            /* text-decoration: overline; */

            /* text-decoration: underline red dotted; */
        }

        .box2{
            width: 200px;
            /* 
                white-space 设置网页如何处理空白!!!!!!!!!!!!!
                    可选值:
                        normal 正常
                        nowrap 不换行
                        pre 保留空白

            */
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>
<body>

    <div class="box2">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur, minus fugit in perspiciatis reprehenderit consequuntur aspernatur repellat cumque quidem asperiores quaerat placeat, tenetur vel veritatis deserunt numquam. Dolores, cupiditate enim.
    </div>

    <div class="box1">
        今天天气真不错
    </div>
</body>
</html>

09.背景background

<!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>
        .box1{
            width: 1000px;
            height: 1000px;
            /* 
                background-color 设置背景颜色
             */
            background-color: #bfa;

            /* 
                background-image 设置背景图片 
                    - 可以同时设置背景图片和背景颜色,这样背景颜色将会成为图片的背景色
                    - 如果背景的图片小于元素,则背景图片会自动在元素中平铺将元素铺满
                    - 如果背景的图片大于元素,将会一个部分背景无法完全显示
                    - 如果背景图片和元素一样大,则会直接正常显示
                        
            */
            background-image: url("./photo/aa.webp");

            /* 
                background-repeat 用来设置背景的重复方式
                    可选值:
                        repeat 默认值 , 背景会沿着x轴 y轴双方向重复
                        repeat-x 沿着x轴方向重复
                        repeat-y 沿着y轴方向重复
                        no-repeat 背景图片不重复
             */
            background-repeat: no-repeat;

            /*
                background-position 用来设置背景图片的位置
                    设置方式:
                        通过 top left right bottom center 几个表示方位的词来设置背景图片的位置
                            使用方位词时必须要同时指定两个值,如果只写一个则第二个默认就是center

                        通过偏移量来指定背景图片的位置:
                            水平方向的偏移量 垂直方向变量
            */
            background-position: center;
            /* background-position: -50px 300px; */
            
                

        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

10.背景2

<!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>
        .box1{
            width: 500px;
            height: 500px;
            overflow: auto;
            background-color: #bfa;
            background-image: url("./img/2.jpg");
            background-repeat: no-repeat;
            background-position: 0 0;
            padding: 10px;

            /*
                 设置背景的范围 
                    background-clip 
                        可选值:
                            border-box 默认值,背景会出现在边框的下边
                            padding-box 背景不会出现在边框,只出现在内容区和内边距
                            content-box 背景只会出现在内容区

                    background-origin 背景图片的偏移量计算的原点
                            padding-box 默认值,background-position从内边距处开始计算
                            content-box 背景图片的偏移量从内容区处计算
                            border-box 背景图片的变量从边框处开始计算
            */
            /* background-origin: border-box;
            background-clip: content-box; */

            /* 
                background-size 设置背景图片的大小
                    第一个值表示宽度 
                    第二个值表示高度
                    - 如果只写一个,则第二个值默认是 auto

                    cover 图片的比例不变,将元素铺满
                    contain 图片比例不变,将图片在元素中完整显示
            */
            background-size: contain;

            /* 
                background-color
                background-image
                background-repeat
                background-position
                background-size
                background-origin
                background-clip
                background-attachment

                - backgound 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
                    并且该样式没有顺序要求,也没有哪个属性是必须写的

                    注意:
                        background-size必须写在background-position的后边,并且使用/隔开
                            background-position/background-size

                        background-origin background-clip 两个样式 ,orgin要在clip的前边
                

            
             */




        }

        .box2{
            width: 300px;
            height: 1000px;
            background-image: url('./img/1.png');
            background-repeat: no-repeat;
            background-position: 100px 100px;

            /* 
            background-attachment
                - 背景图片是否跟随元素移动
                - 可选值:
                    scroll 默认值 背景图片会跟随元素移动
                    fixed 背景会固定在页面中,不会随元素移动
             */
            background-attachment: fixed;
        }

        .box3{
            border: 10px red double;
            padding: 50px;
            width: 500px;
            height: 500px;
            background: url('./img/2.jpg') #bfa  center center/contain border-box content-box no-repeat ;
        }

    </style>
</head>
<body>
    <div class="box3">

    </div>
    <!-- <div class="box1">
        <div class="box2">
            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Totam aut, odio iusto accusantium ipsum aliquid omnis facere sapiente, nobis vel dicta alias ducimus. Repellat similique unde eius tempore, quia quo.
            Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusantium, accusamus quibusdam. Adipisci in dolorem qui accusantium accusamus voluptatibus magnam nesciunt minus enim quaerat! Quidem, rem. Ipsum amet praesentium enim aliquid!
            Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam provident repellendus ipsum dolorum optio quo, iure eveniet beatae cupiditate rerum minus corporis illum aliquam illo ut quidem aliquid expedita deserunt.
        </div>
    </div> -->
</body>
</html>

11.渐变background-image

<!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>
        .box1{
            width: 200px;
            height: 200px;
            /* background-color: #bfa; */
            /* 
                通过渐变可以设置一些复杂的背景颜色,可以实现从一个颜色向其他颜色过渡的效果
                !!渐变是图片,需要通过background-image来设置

                线性渐变,颜色沿着一条直线发生变化
                    linear-gradient()

                    linear-gradient(red,yellow) 红色在开头,黄色在结尾,中间是过渡区域
                    - 线性渐变的开头,我们可以指定一个渐变的方向
                        to left
                        to right
                        to bottom
                        to top
                        deg deg表示度数
                        turn 表示圈

                    - 渐变可以同时指定多个颜色,多个颜色默认情况下平均分布,
                        也可以手动指定渐变的分布情况

                    repeating-linear-gradient() 可以平铺的线性渐变
             */
            
            /* background-image: linear-gradient(red,yellow,#bfa,orange); */
            /* background-image: linear-gradient(red 50px,yellow 100px, green 120px, orange 200px); */
            background-image: repeating-linear-gradient(to right ,red, yellow 50px);

        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

12.径向渐变radial-gradient()

<!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>
        .box1{
            width: 300px;
            height: 300px;

/* 
            radial-gradient() 径向渐变(放射性的效果) */
            /* 
                 默认情况下径向渐变的形状根据元素的形状来计算的
                    正方形 --> 圆形
                    长方形 --> 椭圆形
                    - 我们也可以手动指定径向渐变的大小
                    circle
                    ellipse

                    - 也可以指定渐变的位置
                    - 语法:
                        radial-gradient(大小 at 位置, 颜色 位置 ,颜色 位置 ,颜色 位置)
                            大小:
                                circle 圆形
                                ellipse 椭圆
                                closest-side 近边	
                                closest-corner 近角
                                farthest-side 远边
                                farthest-corner 远角

                            位置:
                                top right left center bottom
       
             */

            background-image: radial-gradient(farthest-corner at 100px 100px, red , #bfa)
        }
    </style>
</head>
<body>
    <div class="box1"></div>
</body>
</html>

animation

01.过渡transition

<!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;
        }

        .box1{
            width: 800px;
            height: 800px;
            background-color: silver;
            overflow: hidden;
        }

        .box1 div{
            width: 100px;
            height: 100px;
            margin-bottom: 100px;
            margin-left: 0;
            
        }

        .box2{
            background-color: #bfa;
            /* margin-left: auto; */
            /* transition:all 2s; */
            /* 
                过渡(transition)
                    - 通过过渡可以指定一个属性发生变化时的切换方式
                    - 通过过渡可以创建一些非常好的效果,提升用户的体验
             */

             /* 
             transition-property: 指定要执行过渡的属性  
                多个属性间使用,隔开 
                如果所有属性都需要过渡,则使用all关键字
                大部分属性都支持过渡效果,注意过渡时必须是从一个有效数值向另外一个有效数值进行过渡
             */
            /* transition-property: height , width; */
            /* transition-property: all; */

             /*
              transition-duration: 指定过渡效果的持续时间
                时间单位:s 和 ms  1s = 1000ms
              */
             /* transition-duration: 100ms, 2s; */
             /* transition-duration: 2s; */

             /* 
             transition-timing-function: 过渡的时序函数
                指定过渡的执行的方式  
                可选值:
                    ease 默认值,慢速开始,先加速,再减速
                    linear 匀速运动
                    ease-in 加速运动
                    ease-out 减速运动
                    ease-in-out 先加速 后减速
                    cubic-bezier() 来指定时序函数
                        https://cubic-bezier.com
                    steps() 分步执行过渡效果
                        可以设置一个第二个值:
                            end , 在时间结束时执行过渡(默认值)
                            start , 在时间开始时执行过渡
             */
             /* transition-timing-function: cubic-bezier(.24,.95,.82,-0.88); */
             /* transition-timing-function: steps(2, start); */


             /* 
             transition-delay: 过渡效果的延迟,等待一段时间后在执行过渡  
             */
             /* transition-delay: 2s; */
             

             /* transition 可以同时设置过渡相关的所有属性,只有一个要求,如果要写延迟,则两个时间中第一个是持续时间,第二个是延迟 */
             transition:2s margin-left 1s cubic-bezier(.24,.95,.82,-0.88);
        }

        .box3{
            background-color: orange;
            transition-property: all;
            transition-duration: 2s;
        }

        .box1:hover div{
            /* width: 200px;
            height: 200px; */
            /* background-color: orange; */
            margin-left: 700px;
        }
    </style>

</head>
<body>

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

02.动画animation

<!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;
        }

        .box1{
            width: 800px;
            height: 800px;
            background-color: silver;
            overflow: hidden;
        }

        .box1 div{
            width: 100px;
            height: 100px;
            margin-bottom: 100px;
            margin-left: 10px;
            
        }

        .box2{
            background-color: #bfa;
            

            /* 设置box2的动画 */
            /* animation-name: 要对当前元素生效的关键帧的名字 */
            /* animation-name: test; */

            /* animation-duration: 动画的执行时间 */
            /* animation-duration: 4s; */

            

            /* 动画的延时 */
            /* animation-delay: 2s; */

            /* animation-timing-function: ease-in-out; */

            /* 
            animation-iteration-count 动画执行的次数 
                可选值:
                    次数
                    infinite 无限执行
            */
            /* animation-iteration-count: 1; */

            /*
             animation-direction
                指定动画运行的方向
                    可选值:
                    normal 默认值  从 from 向 to运行 每次都是这样 
                    reverse 从 to 向 from 运行 每次都是这样 
                    alternate 从 from 向 to运行 重复执行动画时反向执行
                    alternate-reverse 从 to 向 from运行 重复执行动画时反向执行

            */
            /* animation-direction: alternate-reverse; */

            /* 
                animation-play-state: 设置动画的执行状态 
                可选值:
                    running 默认值 动画执行
                    paused 动画暂停
            */
            /* animation-play-state: paused; */

            /* 
            animation-fill-mode: 动画的填充模式
                可选值:
                    none 默认值 动画执行完毕元素回到原来位置
                    forwards 动画执行完毕元素会停止在动画结束的位置
                    backwards 动画延时等待时,元素就会处于开始位置
                    both 结合了forwards 和 backwards
            */
            /* animation-fill-mode: both; */
            animation: test 2s infinite 5s alternate;
            /* animation:关键帧 单次执行时间 执行次数 首次执行前延迟时间 指定动画运行的方向 */
            
        }

        .box1:hover div{
            animation-play-state: paused;
        }

        /* 
        动画
            动画和过渡类似,都是可以实现一些动态的效果,
                不同的是过渡需要在某个属性发生变化时才会触发
                动画可以自动触发动态效果
                
            设置动画效果,必须先要设置一个关键帧,关键帧设置了动画执行每一个步骤
        */
        @keyframes test {
            /* from表示动画的开始位置 也可以使用 0% */
            from{
                margin-left: 0;
                background-color: orange;
            } 

            /* to动画的结束位置 也可以使用100%*/
            to{
                background-color: red;
                margin-left: 700px;
            }
        }
    </style>

</head>
<body>

    <div class="box1">
        <div class="box2"></div>
        <!-- <div class="box3"></div> -->
    </div>
    
</body>
</html>

小球下落

<!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>

        .outer{
            height: 500px;
            border-bottom: 10px black solid;
            margin: 50px auto;
            overflow: hidden;
        }
        .outer div{
            float: left;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: #bfa;
            animation: ball .5s forwards linear infinite alternate;
        }

        div.box2{
            background-color: orange;
            animation-delay: .1s;
        }

        div.box3{
            background-color: yellow;
            animation-delay: .2s;
        }

        div.box4{
            background-color: yellowgreen;
            animation-delay: .3s;
        }

        div.box5{
            background-color: blue;
            animation-delay: .4s;
        }
        div.box6{
            background-color: pink;
            animation-delay: .5s;
        }
        div.box7{
            background-color: tomato;
            animation-delay: .6s;
        }
        div.box8{
            background-color: skyblue;
            animation-delay: .7s;
        }
        div.box9{
            background-color: chocolate;
            animation-delay: .8s;
        }

        /* 创建小球下落的动画 */
        @keyframes ball {
            from{
                margin-top: 0;
            }

            to{
                margin-top: 400px;
            }

            /* 2                                    to{
                margin-top: 400px;
                animation-timing-function: ease-in;
            }

            40%{
                margin-top: 100px;
            }

            80%{
                margin-top: 200px;
            } */

        }
    </style>
</head>
<body>

    <div class="outer">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
        <div class="box4"></div>
        <div class="box5"></div>
        <div class="box6"></div>
        <div class="box7"></div>
        <div class="box8"></div>
        <div class="box9"></div>
    </div>
    
</body>
</html>

04.变形transform

<!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>
        body{
            background-color: rgb(236, 236, 236);
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin: 0 auto;
            margin-top: 200px;

            /* 
                变形就是指通过CSS来改变元素的形状或位置
                -   变形不会影响到页面的布局
                - transform 用来设置元素的变形效果
                    - 平移:
                        translateX() 沿着x轴方向平移
                        translateY() 沿着y轴方向平移
                        translateZ() 沿着z轴方向平移
                            - 平移元素,百分比是相对于自身计算的
            */
            /* transform: translateY(-100px); */
            transform: translateX(100%);
        }

        /* .box2{
            width: 200px;
            height: 200px;
            background-color: orange;
            margin: 0 auto;
        } */

        .box3{
            background-color: orange;
            position: absolute;
            /* 
                这种居中方式,只适用于元素的大小确定
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto; */

            left: 50%;
            top: 50%;
            transform: translateX(-50%) translateY(-50%);
          
        }

        .box4, .box5{
            width: 220px;
            height: 300px;
            background-color: #fff;
            float: left;
            margin: 0 10px;
            transition:all .3s;
        }

        .box4:hover,.box5:hover{
            transform: translateY(-4px);
            box-shadow: 0 0 10px rgba(0, 0, 0, .3)
        }
    </style>
</head>
<body>

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

    <div class="box2"></div>

    <!-- <div class="box3">
        aaaa
    </div> -->

    <div class="box4">

    </div>

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

05.z轴平移transform: translateZ(???px)

<!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>
        html{
            /* 设置当前网页的视距为800px,人眼距离网页的距离 */
            perspective: 800px;
        }

        body{
            border: 1px red solid;/*这才是body的真实所占空间*/
            background-color: rgb(241, 241, 241);/*html更改的是html的背景颜色*/
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin: 200px auto;
            /* 
                z轴平移,调整元素在z轴的位置,正常情况就是调整元素和人眼之间的距离,
                    距离越大,元素离人越近
                z轴平移属于立体效果(近大远小),默认情况下网页是不支持透视,如果需要看见效果
                    必须要设置网页的视距
            */

            transition:2s;
        }

        body:hover .box1{
            transform: translateZ(800px);
        }
    </style>
</head>
<body>

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

06.旋转rotate

<!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>
        html{
            perspective: 800px;
        }

        body{
            border: 1px red solid;
            background-color: rgb(241, 241, 241);
        }
        .box1{
            width: 320px;
            height: 320px;
            background-color: #bfa;
            margin: 200px auto;

            transition:5s;
        }

        body:hover .box1{

            /*
                通过旋转可以使元素沿着x y 或 z旋转指定的角度
                    rotateX()
                    rotateY()
                    rotateZ()
            */
            /* transform: rotateZ(.25turn); */
            /* transform: rotateY(180deg) translateZ(400px); */
            /* transform: translateZ(400px) rotateY(180deg) ; */
            transform: rotateY(180deg);
            /* 是否显示元素的背面 */
            /* backface-visibility: hidden; */


        }
    </style>
</head>
<body>

    <div class="box1">
        <img src="../gg.webp" alt="">
    </div>
    
</body>
</html>

07.缩放scaleX()

<!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>
        html{
            perspective:800px;
            
        }
        .box1{
            width: 100px;
            height: 100px;
            background-color: #bfa;
            transition:2s;
            margin: 100px auto;


            /* 变形的原点 默认值 center*/
            /* transform-origin:20px 20px;  */
        }

        .box1:hover{
            /* 
                对元素进行缩放的函数:
                    scaleX() 水平方向缩放
                    scaleY() 垂直方向缩放
                    scale() 双方向的缩放
            */
            transform:scale(2)
        }


        .img-wrapper{
            width: 200px;
            height: 200px;
            border: 1px red solid;
            overflow: hidden;
        }

        img{
            transition: .2s;
        }

        .img-wrapper:hover img{
            transform:scale(1.2);
        }

    </style>
</head>
<body>
    
    <div class="box1"></div>

    <div class="img-wrapper">
        <img src="an.jpg" width="100%">
    </div>


</body>
</html>

弹性盒

01.弹性盒display: flex;

<!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;
            list-style: none;
        }

        ul{
            width: 500px;
            border: 10px red solid;
            /* 将ul设置为弹性容器 */
            display: flex;

            /* 
               flex-direction 指定容器中弹性元素的排列方式
                可选值:
                    row 默认值,弹性元素在容器中水平排列(左向右)
                        - 主轴 自左向右
                    row-reverse 弹性元素在容器中反向水平排列(右向左)
                        - 主轴 自右向左
                    column 弹性元素纵向排列(自上向下)
                    column-reverse 弹性元素方向纵向排列(自下向上)

                主轴:
                    弹性元素的排列方向称为主轴
                侧轴:
                    与主轴垂直方向的称为侧轴

            */

            flex-direction: row;
        }

        li{
            width: 200px;
            height: 100px;
            background-color: #bfa;
            font-size: 50px;
            text-align: center;
            line-height: 100px;

            /* 
                弹性元素的属性:
                    flex-grow 指定弹性元素的伸展的系数:
                    - 当父元素有多余空间的时,子元素如何伸展
                    - 将父元素的剩余空间按照比例进行分配后,添加到各元素身上
                    flex-shrink 指定弹性元素的收缩系数
                    - 当父元素中的空间不足以容纳所有的子元素时,如果对子元素进行收缩
            */
            /* flex-grow: 1; */

            /* 
            
            */
            flex-shrink: 0;

            
        }
        li:nth-child(1){
            flex-grow: 0;
            flex-shrink: 1;
        }

        li:nth-child(2){
            background-color: pink;
            /* flex-grow: 2; */
            flex-shrink: 2;
        }

        li:nth-child(3){
            background-color: orange;
            /* flex-grow: 3; */
            flex-shrink: 3;
        }
    </style>
</head>
<body>
    <!-- 
        flex(弹性盒、伸缩盒)
            - 是CSS中的又一种布局手段,它主要用来代替浮动来完成页面的布局
            - flex可以使元素具有弹性,让元素可以跟随页面的大小的改变而改变
            - 弹性容器
                - 要使用弹性盒,必须先将一个元素设置为弹性容器
                - 我们通过 display 来设置弹性容器
                    display:flex  设置为块级弹性容器
                    display:inline-flex 设置为行内的弹性容器

            - 弹性元素
                - 弹性容器的子元素是弹性元素(弹性项)
                - 弹性元素可以同时是弹性容器

     -->

     <ul>
         <li>1</li>
         <li>2</li>
         <li>3</li>
     </ul>

</body>
</html>

02.弹性容器的样式flex-direction: column; flex-wrap: flex-flow justify-content

<!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;
            list-style: none;
        }

        ul{
            width: 800px;
            border: 10px red solid;
          /* 设置ul为弹性容器 */
            display: flex;

            /* flex-direction: column; */

            /* flex-wrap: 
                设置弹性元素是否在弹性容器中自动换行
                可选值:
                    nowrap 默认值,元素不会自动换行
                    wrap 元素沿着辅轴方向自动换行
                    wrap-reverse 元素沿着辅轴反方向换行
            */

            /* flex-wrap: wrap-reverse; */

            /* flex-flow:  wrap 和 direction 的简写属性 */
            /* flex-flow: row wrap; */


            /*  
                justify-content
                    - 如何分配主轴上的空白空间(主轴上的元素如何排列)
                    - 可选值:
                        flex-start 元素沿着主轴起边排列
                        flex-end 元素沿着主轴终边排列
                        center 元素居中排列
                        space-around 空白分布到元素两侧
                        space-between 空白均匀分布到元素间
                        space-evenly 空白分布到元素的单侧

            */
            /* justify-content: center; */
        }

        li{
            width: 200px;
            height: 100px;
            background-color: #bfa;
            font-size: 50px;
            text-align: center;
            line-height: 100px;
            flex-shrink: 0;


            
        }
        /* li:nth-child(1){
        } */

        li:nth-child(2){
            background-color: pink;
        }

        li:nth-child(3){
            background-color: orange;
        }
    </style>
</head>
<body>
    

     <ul>
         <li>1</li>
         <li>2</li>
         <li>3</li>
     </ul>

</body>
</html>

03.弹性容器的样式

<!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;
            list-style: none;
        }

        ul{
            width: 600px;
            height: 800px;
            border: 10px red solid;
          /* 设置ul为弹性容器 */
            display: flex;

            /* flex-direction: column; */

            /* flex-wrap: 
                设置弹性元素是否在弹性容器中自动换行
                可选值:
                    nowrap 默认值,元素不会自动换行
                    wrap 元素沿着辅轴方向自动换行
                    wrap-reverse 元素沿着辅轴反方向换行
            */

            /* flex-wrap: wrap-reverse; */

            /* flex-flow:  wrap 和 direction 的简写属性 */
            flex-flow: row wrap;


            /*  
                justify-content
                    - 如何分配主轴上的空白空间(主轴上的元素如何排列)
                    - 可选值:
                        flex-start 元素沿着主轴起边排列
                        flex-end 元素沿着主轴终边排列
                        center 元素居中排列
                        space-around 空白分布到元素两侧
                        space-between 空白均匀分布到元素间
                        space-evenly 空白分布到元素的单侧

            */
            /* justify-content: center; */

            /*
             align-items: 
                - 元素在辅轴上如何对齐
                - 元素间的关系
                    - 可选值:
                        stretch 默认值,将元素的长度设置为相同的值
                        flex-start 元素不会拉伸,沿着辅轴起边对齐
                        flex-end 沿着辅轴的终边对齐
                        center 居中对齐
                        baseline 基线对齐
             */

             justify-content: center;

             /* align-content: 辅轴空白空间的分布 */
             /* 可选值:
                        stretch 默认值,将元素的长度设置为相同的值
                        flex-start 元素不会拉伸,沿着辅轴起边对齐
                        flex-end 沿着辅轴的终边对齐
                        center 居中对齐
                        baseline 基线对齐
             align-items: flex-start; */
             align-content: space-between;
            
        }

        li{
            width: 200px;
            background-color: #bfa;
            font-size: 50px;
            text-align: center;
            line-height: 100px;
            flex-shrink: 0;


            
        }
        li:nth-child(1){
            /* align-self: 用来覆盖当前弹性元素上的align-items */
            align-self: stretch;
        }

        li:nth-child(2){
            background-color: pink;
        }

        li:nth-child(3){
            background-color: orange;
        }

        li:nth-child(4){
            background-color: yellow;
        }

        li:nth-child(5){
            background-color: chocolate;
        }
    </style>
</head>
<body>
    

     <ul>
         <li>1</li>
         <li>
             2
            <div>2</div>
         </li>
         <li>
             3
             <div>3</div>
             <div>3</div>
        </li>

        <li>1</li>

        <li>
                2
               <div>2</div>
            </li>
     </ul>

</body>
</html>

04.弹性元素的样式

<!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;
            list-style: none;
        }

        ul{
            width: 900px;
            border: 10px red solid;
            /* 设置弹性盒 */
            display: flex;
        
        }

        li{
            width: 200px;
            height: 100px;
            background-color: #bfa;
            font-size: 50px;
            text-align: center;
            line-height: 100px;

            /* 
                弹性的增长系数
            */
            /* flex-grow: 1; */

            /*  
            flex-shrink: 1;
                弹性元素的缩减系数
                    - 缩减系数的计算方式比较复杂
                    - 缩减多少是根据 缩减系数 和 元素大小来计算
            */
           

            /* 
                元素基础长度

                flex-basis 指定的是元素在主轴上的基础长度
                    如果主轴是 横向的 则 该值指定的就是元素的宽度
                    如果主轴是 纵向的 则 该值指定的是就是元素的高度
                    - 默认值是 auto,表示参考元素自身的高度或宽度
                    - 如果传递了一个具体的数值,则以该值为准
            */
            /* flex-basis: auto; */

            /* 
                flex 可以设置弹性元素所有的三个样式
                    flex 增长 缩减 基础;
                        initial "flex: 0 1 auto".
                        auto  "flex: 1 1 auto"
                        none "flex: 0 0 auto" 弹性元素没有弹性
            */
            flex: initial;

            
        }
        li:nth-child(1){
            /* order 决定弹性元素的排列顺序 */
            order: 2;
        }

        li:nth-child(2){
            background-color: pink;
            /* flex-grow: 2; */
            order: 3;
        }

        li:nth-child(3){
            background-color: orange;
            /* flex-grow: 3; */
            order: 1;
        }
    </style>
</head>
<body>
    

     <ul>
         <li>1</li>
         <li>2</li>
         <li>3</li>
     </ul>

</body>
</html>

移动端

1像素

<!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>
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>
<body>

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


    <!-- 
        像素:
            - 屏幕是由一个一个发光的小点构成,这一个个的小点就是像素
            - 分辨率:1920 x 1080 说的就是屏幕中小点的数量
            - 在前端开发中像素要分成两种情况讨论:CSS像素 和 物理像素
            - 物理像素,上述所说的小点点就属于物理像素
            - CSS像素,编写网页时,我们所用像素都是CSS像素
                - 浏览器在显示网页时,需要将CSS像素转换为物理像素然后再呈现
                - 一个css像素最终由几个物理像素显示,由浏览器决定:
                    默认情况下在pc端,一个css像素 = 一个物理像素

        视口(viewport)
            - 视口就是屏幕中用来显示网页的区域
            - 可以通过查看视口的大小,来观察CSS像素和物理像素的比值
            - 默认情况下:
                视口宽度 1920px(CSS像素)
                        1920px(物理像素)
                        - 此时,css像素和物理像素的比是 1:1

            - 放大两倍的情况:
                视口宽度 960px(CSS像素)
                        1920px(物理像素)
                        - 此时,css像素和物理像素的比是1:2

            - 我们可以通过改变视口的大小,来改变CSS像素和物理像素的比值



     -->
    
</body>
</html>

移动端

<!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>
        .box1{
            width: 900px;
            height: 100px;
            background-color: #bfa;
        }
    </style>
</head>
<body>
    <!-- 
        在不通的屏幕,单位像素的大小是不同的,像素越小屏幕会越清晰
            24寸 1920x1080
            i6 4.7寸 750 x 1334

            智能手机的像素点 远远小于 计算机的像素点

            问题:一个宽度为900px的网页在iphone6中要如何显示呢?

            默认情况下,移动端的网页都会将视口设置为980像素(css像素)
                以确保pc端网页可以在移动端正常访问,但是如果网页的宽度超过了980,
                    移动端的浏览器会自动对网页缩放以完整显示网页

            https://material.io/resources/devices/


            所以基本大部分的pc端网站都可以在移动端中正常浏览,但是往往都不会有一个好的体验,
                为了解决这个问题,大部分网站都会专门为移动端设计网页


     -->

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

移动端页面

<!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">

    <!-- 设置视口大小 device-width表示设备的宽度(完美视口)-->
    <!-- <meta name="viewport" content="width=device-width"> -->
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box1{
            width: 100px;
            height: 100px;
            background-color: red;

        }
    </style>
</head>
<body>
    <!-- 
        移动端默认的视口大小是980px(css像素),
            默认情况下,移动端的像素比就是  980/移动端宽度  (980/750)
            如果我们直接在网页中编写移动端代码,这样在980的视口下,像素比是非常不好,
                导致网页中的内容非常非常的小
            编写移动页面时,必须要确保有一个比较合理的像素比:
                1css像素 对应 2个物理像素
                1css像素 对应 3个物理像素

            - 可以通过meta标签来设置视口大小

            - 每一款移动设备设计时,都会有一个最佳的像素比,
                一般我们只需要将像素比设置为该值即可得到一个最佳效果
                将像素比设置为最佳像素比的视口大小我们称其为完美视口

                将网页的视口设置为完美视口
                <meta name="viewport" content="width=device-width, initial-scale=1.0">

                结论:以后再写移动端的页面,就把上边这个玩意先写上

     -->
    <div class="box1"></div>
</body>
</html>

08.视口

<!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;
        }
        .box1{
            width: 6.4vw;
            height: 4.667vw;
            background-color: #bfa;
        }
    </style>
</head>
<body>

    <!-- 
        不同的设备完美视口的大小是不一样的
            iphone6 -- 375
            iphone6plus -- 414

        由于不同设备视口和像素比不同,所以同样的375个像素在不同的设备下意义是不一样,
            比如在iphone6中 375就是全屏,而到了plus中375就会缺一块

        所以在移动端开发时,就不能再使用px来进行布局了

        vw 表示的是视口的宽度(viewport width)
            - 100vw = 一个视口的宽度
            - 1vw = 1%视口宽度

            vw这个单位永远相当于视口宽度进行计算

            设计图的宽度
                750px 1125px

            设计图 
                750px  

            使用vw作为单位
                100vw

            创建一个 48px x 35px 大小的元素

            100vw = 750px(设计图的像素) 0.1333333333333333vw = 1px
            6.4vw = 48px(设计图像素)
            4.667vw = 35px

    -->
    <div class="box1">
    </div>
    
</body>
</html>

09.vw适配

<!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;
        }

        html{
            /* 
                网页中字体大小最小是12px,不能设置一个比12像素还小的字体
                    如果我们设置了一个小于12px的字体,则字体自动设置为12

                0.1333333vw = 1px

                5.3333vw = 40px
            */
            font-size: 5.3333vw;
        }

        .box1{
            /* 
                rem
                    - 1 rem = 1 html的字体大小
                    - 1 rem = 40 px(设计图)
            */
            width: 18.75rem;
            height: 0.875rem;
            background-color: #bfa;
        }
    </style>
</head>
<body>

    <!-- 
        48 x 35
     -->
     <div class="box1"></div>
    
</body>
</html>

10.响应式布局

<!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>
        /*
         使用媒体查询 
            语法: @media 查询规则{}
                媒体类型:
                    all 所有设备
                    print 打印设备
                    screen 带屏幕的设备
                    speech 屏幕阅读器
                    - 可以使用,连接多个媒体类型,这样它们之间就是一个或的关系

                可以在媒体类型前添加一个only,表示只有。
                    only的使用主要是为了兼容一些老版本浏览器
         */

        /* @media print,screen{
            body{
                background-color: #bfa;
            }
        } */

        @media only screen {
            body{
                background-color: #bfa;
            }
        }
    </style>
</head>
<body>
    <!-- 
        响应式布局
            - 网页可以根据不通的设备或窗口大小呈现出不同的效果
            - 使用响应式布局,可以使一个网页适用于所有设备
            - 响应布局的关键就是 媒体查询
            - 通过媒体查询,可以为不通的设备,或设备不同状态来分别设置样式
     -->
    
</body>
</html>

11.媒体查询

<!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>
        /*
             媒体特性:
                width 视口的宽度
                height 视口的高度

                min-width 视口的最小宽度(视口大于指定宽度时生效)
                max-width 视口的最大宽度(视口小于指定宽度时生效)
         */

         /* @media (max-width: 500px){
             body{
                background-color: #bfa;
             }
         } */

/* 
         样式切换的分界点,我们称其为断点,也就是网页的样式会在这个点时发生变化
         一般比较常用的断点

         小于768 超小屏幕 max-width=768px
         大于768 小屏幕   min-width=768px
         大于992 中型屏幕 min-width=992px
         大于1200 大屏幕  min-width=1200px

*/
         @media only screen and (min-width: 500px) and (max-width:700px){
             body{
                background-color: #bfa;
             }
         }
    </style>
</head>
<body>
    
</body>
</html>```

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值