2022-08-23 第二小组 张明旭 前端学习记录

目录

重点归纳

知识点

 CSS三大特性

1.层叠性

2. 继承性

3.优先级

 常用的单位

字体和图片的使用

列表、边界样式

练习

盒子模型

定位

定位的left、margin-left的区别

图片隐藏及小动画

鼠标放在图片上之前

鼠标放在图片上之后

浮动

 内容坍塌与清除浮

 解决:清除列表ul中的浮动


重点归纳

  • CSS三大特性
  • CSS选择器*****
  • 盒子模型
  • 定位
  • 浮动
  • 元素的隐藏

知识点

 CSS三大特性

1.层叠性

        一个标签可以有多个CSS样式

        浏览器处理冲突的能力:如果一个属性通过两个相同的选择器设置到元素上,样式的层叠规则按照样式的声明顺序来层叠,就近原则

        前提:选择器必须是同一种(例如都是类选择器)

        样式不冲突不会层叠

<!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>
        .fontStyle{
            color: yellow;
            font-size: 20px;
        }
        .a{
            color: red;
        }
        .backgroundStyle{
            background-color: green;
        }
    </style>
</head>
<body>
<-- 三个类选择器作用于h1 -->
<h1 class="a fontStyle backgroundStyle">我是H1标签</h1>
</body>
</html>

2. 继承性

        子标签会继承父标签的某些样式

        比如说文本的颜色、字号

        但是文本样式不会继承

3.优先级

权重:

            (1)继承的权重=0:优先级最低

            (2)行内样式权重=100:优先级很高

            (3)权重相同时:就近原则,谁先声明谁在前。

            (4)!important:定义优先级

CSS权重公式:

  1.             继承、*                   0,0,0,0
  2.             标签选择器                0,0,0,1
  3.             类、伪类选择器            0,0,1,0
  4.             ID选择器                 0,1,0,0
  5.             行内样式                 1.0.0.0
  6.             !important              无穷大
  7.             width、height            大于无穷大
  8.             max-width、max-height    大于无穷大
  9.             min-width、min-height    大于无穷大

!important:如果同时有max-width、max-height,!important是不管用的

例子:

            选择器 div ul li {}的权重等于他们的权重相加:0,0,0,3

            li{} 的权重等于:0,0,0,1

例子:

            a:link{}的权重=0,0,1,1

            div a {}的权重=0,0,0,2

权重不能被继承

贡献值没有进位

前提:CSS样式发生冲突

<!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>
 
        h1{
            color: blue;
        }
        .div{
            height: 200px;
            width: 200px;
        }
        p{
            background-color: blueviolet !important;
        }

        /* div下的ul下的li */
        div ol li{
            color: red;
        }

        /* 这个页面上所有的li */
        li{
            color: yellow;
        }

        a:link{
            color: red;
        }

        div a {
            color: yellow;
        }
    </style>
</head>
<body>
<div class=backgroundStyle>
    <p style="background-color: red;">我是div里的p</p>
</div>

<div>
    <ol>
        <li>123456</li>
        <li>123456</li>
        <li>123456</li>
    </ol>
</div>
<div>
    <a href="#">a标签</a>
</div>
</body>
</html>

 常用的单位

  1. px:像素(最常用)
  2. em:绝对单位,例如父级的像素字号为16px,我可以设置成2em,父类字号的2倍
  3. rem:由整个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>
        p {
            /* 字体大小 */
            font-size: 20px;
            /* 字体样式 */
            font-style: italic;
            /* 字体粗细 */
            font-weight: bold;
            /* 字体修饰:取消下划线、上划线、删除线 等 */
            text-decoration: none;
            /* 字体 */
            font-family: monospace;
            /* 复合属性:直接定义多个font开头的属性 */
            font: 30px italic bold;
        }
        div {
            background-color: white;
            width: 800px;
            height: 400px;
            background-image: url(./css/timg-10.jpeg);
            /* 图片默认平铺,多个图片占满区域 */
            background-size: 400px;
            /* 不平铺 */
            background-repeat: no-repeat;
            /* 图片位置,默认上左 */
            background-position: center;
            /* 有复合属性 */
            /* background:  no-repeat center; */
        }
    </style>
</head>
<body>
    <input type="color">
    <div>
        <p>我是div里的p</p>
    </div>
</body>
</html>

列表、边界样式

<!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 ul li{
            /* 列表前的标识 */
            /* 空心圆 */
            list-style-type: circle;
            /* 使用图片当做列表前的序号 */
            list-style-image: url(./css/timg-10.jpeg);
        }
        .div1 {
            width: 200px;
            height: 200px;
            background-color: yellow;
            /* 圆角:像素为半径 */
            border-radius: 50px;
            border-bottom-left-radius: 100px;
            /* 边界框样式:虚线 */
            border-style: dashed;
            /* 边界颜色 */
            border-color: blueviolet;
        }
    </style>
</head>
<body>
    <div>
        <ul>
            <li>111</li>
            <li>222</li>
            <li>333</li>
            <li>444</li>
            <li>555</li>
            <li>666</li>
        </ul>
    </div>
    <div class="div1"></div>
</body>
</html>

结果

 

练习

<!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 {
            width: 200px;
            height: 200px;
            /* display显示 */
            display: inline-block;
        }

        .div1,
        .div4 {
            border-bottom-left-radius: 50%;
            border-top-right-radius: 50%;
        }

        .div2,
        .div3 {
            border-bottom-right-radius: 50%;
            border-top-left-radius: 50%;
        }

        /* 区块属性:定义一个元素的显示方式 */
        .div1 {
            background-color: green;
        }

        .div2 {
            background-color: blue;
        }

        .div3 {
            background-color: yellow;
        }

        .div4 {
            background-color: red;
        }

        .div5 {
            background-color: orange;
            /* 隐藏元素 */
            display: none;
        }
    </style>
</head>

<body>
    <div class="div1"> </div>
    <div class="div2"> </div>
    <br>
    <div class="div3"> </div>
    <div class="div4"> </div>
    <div class="div5"></div>
</body>

</html>

结果: 

盒子模型

div、a、span都是盒子

一个盒子中主要的属性有5个:width、height、padding、border、margin。

  1. width和height:内容的宽度、高度(不是盒子的宽度、高度)。
  2. padding:内边距。
  3. border:边框。
  4. margin:外边距。
<!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>
        .div1{
            width: 300px;
            height: 300px;
            background-color: orange;
            /* 外边距 */
            margin-top: 100px;
            margin-left: 100px;
            /* 内边距 */
            padding: 20px;
            border: 10px solid red;
            /* border-box:保证盒子的大小是300*300 ,不包括外边距*/
            /* box-sizing: border-box; */
            /* content-box保证div的大小为300*300,不包括内边距和边框线 */
            box-sizing: content-box;
            /* 
            掌握:
                会算盒子的尺寸
            */
        }
        .div2{
            width: 300px;
            height: 300px;
            background-color: orange;
            /* 可见性:隐藏盒子模型
            display: none; */    
            /* 溢出策略:例如:加滑动条、溢出部分隐藏等 */
            overflow: scroll;
        }
    </style>
</head>
<body>
    <!-- 盒子模型 -->
    <div class="div1"></div>
    <div class="div2">
        <img src="../img/timg-10.jpeg" alt="">
    </div>
</body>
</html>

定位

文档流
        在网页中将窗体自上而下分为多个行
        并在每行从左到右的顺序排列元素,即为文档流


        定位position:让一些元素脱离文档流
        1.static:默认的文档流,自上而下,从左到右
        2.absolute:绝对定位
            相对一个父元素的绝对定位
            当设置了绝对定位之后,原来的元素会脱离文档流,在页面上浮起来
        3.relative:相对定位
            相当于上一个元素的位置进行定位,还是在文档流中,没有浮起来
        4.fixed:固定行为
            固定在页面的一个位置,不是网页的一个位置

父相子绝
父元素相对定位

子元素绝对定位

<!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>
        .div1 {
            width: 300px;
            height: 300px;
            background-color: orange;
            /* 绝对定位 */
            position: absolute;
            left: 150px;
            top: 50px;
            /* 隐藏盒子模型
            display: none; 
            */
        }

        .div2 {
            width: 300px;
            height: 300px;
            background-color: skyblue;
            /* 绝对定位 */
            position: absolute;
            /* 给一个类似于坐标的东西进行定位 */
            left: 150px;
            top: 400px;
            /* 隐藏div2,但不隐藏盒子模型
            visibility: hidden; 
            */
        }

        .container {
            width: 800px;
            height: 800px;
            background-color: pink;
            position: relative;
            left: 200px;
            top: 100px;
        }
        .nav{
            width: 100%;
            height: 100px;
            background-color: red;
            /* 水平居中 */
            margin: auto;
            /* 固定定位 */
            position: fixed;
            /* z轴的索引 */
            z-index: 100;
        }

    </style>
</head>

<body>
      <div class="nav">我是导航栏</div>
    <div class="container">
        <div class="div1"> </div>
        <div class="div2"> </div>
    </div>
</body>

</html>


定位的left、margin-left的区别

用margin移动的位置是相对于它最开始的位置移动,margin是盒子的属性
left等是相对于父元素的位置移动的,left是定位的属性

开发中,用盒子模型就用margin,用定位就用left等
使用定位之后不要用margin,

图片隐藏及小动画

<!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 {
            width: 100px;
            height: 1000px;
            overflow: hidden;
            /* 归于一行
            float: left; */
            display: inline-block;
        }
        div:hover{
            overflow: unset;
            width: 1694px;
            height: 1000px;  
        }
    </style>
</head>

<body>
    <div>
        <img src="../img/timg-10.jpeg" alt="">
    </div>
    <div>
        <img src="../img/timg-10.jpeg" alt="">
    </div>
    <div>
        <img src="../img/timg-10.jpeg" alt="">
    </div>
    <div>
        <img src="../img/timg-10.jpeg" alt="">
    </div>

</body>

</html>

鼠标放在图片上之前

鼠标放在图片上之后

浮动

使元素脱离文档流,(浮起来),进行重新排列,如果位置相同会覆盖文档流中元素

div1、div2、div3浮动之前

<!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>
        .div1{
            width: 300px;
            height: 300px;
            background-color: orange;
            /* float: left; */
        }
        .div2{
            width: 300px;
            height: 300px;
            background-color: skyblue;
            /* float: left; */
        }
        .div3{
            width: 300px;
            height: 300px;
            background-color: green;
            /* float: left; */
        }
    </style>
</head>
<body>
    <!-- 
        浮动
     -->
     <div class="div1"></div>
     <div class="div2"></div>
     <div class="div3"></div>
</body>
</html>

 div1浮动,在左上排序,div1覆盖div2,div3在div2下

<!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>
        .div1{
            width: 300px;
            height: 300px;
            background-color: orange;
            float: left;
        }
        .div2{
            width: 300px;
            height: 300px;
            background-color: skyblue;
            /* float: left; */
        }
        .div3{
            width: 300px;
            height: 300px;
            background-color: green;
            /* float: left; */
        }
    </style>
</head>
<body>
    <!-- 
        浮动
     -->
     <div class="div1"></div>
     <div class="div2"></div>
     <div class="div3"></div>
</body>
</html>

 div1、div2浮动,在左上排列,div1覆盖div3

<!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>
        .div1{
            width: 300px;
            height: 300px;
            background-color: orange;
            float: left;
        }
        .div2{
            width: 300px;
            height: 300px;
            background-color: skyblue;
            float: left;
        }
        .div3{
            width: 300px;
            height: 300px;
            background-color: green;
            /* float: left; */
        }
    </style>
</head>
<body>
    <!-- 
        浮动
     -->
     <div class="div1"></div>
     <div class="div2"></div>
     <div class="div3"></div>
</body>
</html>

 内容坍塌与清除浮

例:

当列表ul中的列都浮动之后,文档流中ul内容、大小为空,页面不显示ul的属性

<!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>
        li{
            list-style: none;
            height: 30px;
            width: 100px;
            float: left;
            background-color: aqua;
            margin-left: 20px;
        }
        ul{
            background-color: pink;
        }
    </style>
</head>
<body>
    <!-- 
        一般用ul>li做导航。不做列表
     -->
    <ul class="ulstyle">
        <li>1111</li>
        <li>2222</li>
        <div style="clear:both"></div>
    </ul>
</body>
</html>

 解决:清除列表ul中的浮动

方法一

<!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>
        li{
            list-style: none;
            height: 30px;
            width: 100px;
            float: left;
            background-color: aqua;
            margin-left: 20px;
        }
        /* 如果不给ul尺寸---内容坍塌 */
        ul{
            background-color: pink;
            /* 设置ul的尺寸随li的尺寸变化自动确定 :
            在ul列表中加div块,清除浮动,解决内容坍塌
            <div style="clear:both"></div>

            */
        }

    </style>
</head>
<body>
    <!-- 
        一般用ul>li做导航。不做列表
     -->
    <ul class="ulstyle">
        <li>1111</li>
        <li>2222</li>
        <div style="clear:both"></div>
    </ul>
</body>
</html>

 方法二

<!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>
        li{
            list-style: none;
            height: 30px;
            width: 100px;
            float: left;
            background-color: aqua;
            margin-left: 20px;
        }
        /* 如果不给ul尺寸---内容坍塌 */
        ul{
            background-color: pink;

        }
        /* 
        清除浮动方法二(推荐):
        通过CSS
        伪类:after,在元素后加入内容。
        */
        .ulstyle:after{
            content: '';
            height: 0;
            width: 0;
            display: block;
            visibility: hidden;
            clear: both;
        }
    </style>
</head>
<body>
    <!-- 
        一般用ul>li做导航。不做列表
     -->
    <ul class="ulstyle">
        <li>1111</li>
        <li>2222</li>
    </ul>
</body>
</html>

CSS3的动画:Transition

<!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{
            /* Transition */
            width: 100px;
            height: 100px;
            background-color: orange;
            /* 动画变化 */
            transition: width 2s ease-in 3s,height 3s,background-color ease-out 2s;
        }
        div:hover{
            width: 500px;
            height: 500px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <!-- 
        CSS3有兼容器的问题
     -->
     <div></div>
</body>
</html>

CSS3的动画:anmiation

<!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>
        .div1 {
            /* 引用自定义动画,延迟时间 */
            animation: myAnim 5s;
        }

        /* 先声明动画,再使用*/
        @keyframes myAnim {
            0% {
                width: 100px;
                height: 100px;
                background-color: orange;
            }

            25% {
                width: 200px;
                height: 200px;
                background-color: blue;
            }

            50% {
                width: 400px;
                height: 400px;
                background-color: red;
                transform: rotate(45deg);
            }

            75% {
                width: 200px;
                height: 200px;
                background-color: blue;
                transform: rotateZ(180deg);
            }

            100% {
                width: 100px;
                height: 100px;
                background-color: orange;
                transform: rotate3d(270deg);
            }
        }
    </style>
</head>

<body>
    <!-- animate -->
    <!-- 
        animate与transition的区别
        transition只能通过固定的属性来开始与结束值
     -->
    <div class="div1">123</div>
</body>

</html>

flex(弹性)布局:了解

<!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>
        .container{
            display: flex;
            /* 排列方向 flex-direction:
            row:从左到右
            row-reverse:从右到左
            */
            flex-direction: row;
            /* 
            
            如果一条轴线(一行)装不下,默认缩小排列在一行中
            也可以选择方式换行:flex-wrap:
            */
            flex-wrap: wrap;
            /* 设置主轴的排列策略(对齐方式) :例如居中*/
            justify-content: center;
            /* 交叉轴*/
            align-items: center;
            /* 父级div与父级div对齐方式 */
            align-content: center;

            align-items:flex-start;
            width: 900px;
            height: 900px;
            background-color: pink;
        }
        .flex1{
            /* 
            row:从左到右
            row-reverse:从右到左
            */
            flex-direction: row;
            width: 200px;
            height: 200px;
            background-color: green;
            order: 1;
                /* 要将哪个项目放大,默认是0 */
                /* flex-grow: 2; */
                /* 要将哪个项目缩小,默认是0 */
                flex-shrink: 20;
                align-self: flex-end;
        }
        .flex2{
            flex-direction: row;
            width: 200px;
            height: 200px;
            background-color: yellow;
            order: -2;
        }
    </style>
</head>
<body>
    <!-- 
        flex(弹性)布局
            块级元素和行内块级元素
        父容器加上display: flex
     -->
     <div class="container">
        container
        <div class="flex1">123</div>
        <div class="flex2">456</div>
        <div class="flex1">123</div>
        <div class="flex2">456</div>
        <div class="flex1">123</div>
        <div class="flex2">456</div>
        <div class="flex1">123</div>
        <div class="flex2">456</div>
     </div>
</body>
</html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习编程?其实不难,不过在学习编程之前你得先了解你的目的是什么?这个很重要,因为目的决定你的发展方向、决定你的发展速度。
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面设计类、前端与移动、开发与测试、营销推广类、数据运营类、运营维护类、游戏相关类等,根据不同的分类下面有细分了不同的岗位。
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生学习Java开发,但要结合自身的情况,先了解自己适不适合去学习Java,不要盲目的选择不适合自己的Java培训班进行学习。只要肯下功夫钻研,多看、多想、多练
Can’t connect to local MySQL server through socket \'/var/lib/mysql/mysql.sock问题 1.进入mysql路径
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 sqlplus / as sysdba 2.普通用户登录
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服务器有时候会断掉,所以写个shell脚本每五分钟去判断是否连接,于是就有下面的shell脚本。
BETWEEN 操作符选取介于两个值之间的数据范围内的值。这些值可以是数值、文本或者日期。
假如你已经使用过苹果开发者中心上架app,你肯定知道在苹果开发者中心的web界面,无法直接提交ipa文件,而是需要使用第三方工具,将ipa文件上传到构建版本,开...
下面的 SQL 语句指定了两个别名,一个是 name 列的别名,一个是 country 列的别名。**提示:**如果列名称包含空格,要求使用双引号或方括号:
在使用H5混合开发的app打包后,需要将ipa文件上传到appstore进行发布,就需要去苹果开发者中心进行发布。​
+----+--------------+---------------------------+-------+---------+
数组的声明并不是声明一个个单独的变量,比如 number0、number1、...、number99,而是声明一个数组变量,比如 numbers,然后使用 nu...
第一步:到appuploader官网下载辅助工具和iCloud驱动,使用前面创建的AppID登录。
如需删除表中的列,请使用下面的语法(请注意,某些数据库系统不允许这种在数据库表中删除列的方式):
前不久在制作win11pe,制作了一版,1.26GB,太大了,不满意,想再裁剪下,发现这次dism mount正常,commit或discard巨慢,以前都很快...
赛门铁克各个版本概览:https://knowledge.broadcom.com/external/article?legacyId=tech163829
实测Python 3.6.6用pip 21.3.1,再高就报错了,Python 3.10.7用pip 22.3.1是可以的
Broadcom Corporation (博通公司,股票代号AVGO)是全球领先的有线和无线通信半导体公司。其产品实现向家庭、 办公室和移动环境以及在这些环境...
发现个问题,server2016上安装了c4d这些版本,低版本的正常显示窗格,但红色圈出的高版本c4d打开后不显示窗格,
TAT:https://cloud.tencent.com/document/product/1340