第三天 标签 样式 - 图1

标签

标签的划分 块级元素 行内块元素 行内元素
组成 h1-h6 p div 列表标签 img、video、audio span,a,格式化标签
大小 写宽高起作用 自身内容大小
排列方式 上下 左右排列

标签的划分

  • 块级元素:h1-h6 、p、 div、ul、ol、li、dl、dt、dd
    • 写宽、高可以起作用
    • 独占一行
    • 排列方式:上下
    • 注意:文字类的元素内不能使用块级元素。 p 标签主要用来存放文字,因此p里面不能放块级元素。
  • 行内元素:span、a、b、strong、em、i、del、s、u、ins
    • 写宽、高不起作用,它的大小是由自身内容决定的
    • 可共占一行
    • 排列方式:左右
  • 行内块元素:img、video、audio

    • 写宽、高可以起作用
    • 可共占一行
    • 排列方式:左右

      标签汇总

  • 标题:h1-h6

  • 段落:p
  • 大盒子:div
  • 小盒子:span
  • 图片:img
  • 超链接:a
  • 格式化标签:b、strong、em、i、del、s、u、ins
  • 列表:ul、ol、li、dl、dt、dd
  • 音视频:audio、video

    display的几个值

  • inline :转换成行内元素 (一般不用,如果需要直接用行内元素即可)

  • block:转换成块级元素
  • inline-block: 转换成行内块
  • none:消失

    面试题:让一个元素消失有几种办法?

  • display:none

  • visibility:hidden;通过改变可见性
  • opacity:0 ;通过改变透明度,取值范围:0~1
  • 定位的元素通过层级来控制(z-index)
  • 可以通过给元素设置margin负值调到屏幕一侧
  • 宽高等于0

    面试题:display和visibility、opacity都可以让元素消失,有啥区别?

    display:none 是彻底的消失,不占位置,但是visibility:hidden;和opacity:0;虽然看不见了,但是位置还在。

    清除列表默认格式

  • * 是通配符选择器,代表选中页面中所有的元素,下面代码的意思就是,把页面中所有元素默认自带的margin值和padding值都归为0.

    1. *{
    2. margin:0;
    3. padding:0;
    4. }
  • 清除列表前面默认的样式

    1. ul,ol{
    2. list-style: none;
    3. }
  • 清除a标签下划线

    1. a{
    2. text-decoration: none;
    3. }
  • 表示一个元素的宽度(width) 高度(height)背景颜色:background-color

    1. <style>
    2. div{
    3. width:200px;
    4. height:200px;
    5. background-color:red;
    6. }
    7. </style>
  • 文字缩进:text-indent

text-indent后面可以跟具体的像素值,也可以跟em,如果是2em的时候代表缩进2个字的距离。

<style>
    p{
        /* text-indent: 10px; */
        text-indent:2em;        
    }
</style>
  • 文字大小:font-size

    p{
    font-size:26px;
    }
    
  • 文字颜色:color

  • 文字字体:font-family

如果是中文字体,或者是英文字体由多个单词组成需要加单引号或者双引号

font-family:"宋体","Times New Roman",Georgia,Serif;
  • 控制文字粗细:font-weight
    • 400 正常粗细===normal
    • 700 ===bold
    • 900 ===bolder

如果用了b、strong,不想让文字加粗,font-weight:normal(400);

<style>
    p{
        font-weight: bold;
    }
    b{  
        /* 400 */
        font-weight: normal;
    }
</style>
  • 控制文字倾斜 :font-style

    • font-style:italic; 让文字倾斜
    • font-style:normal; 让文字正常
      <!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>
      span{
          font-style: italic;
      }
      i{
          font-style:normal;
      }
      </style>
      </head>
      <body>
      <span>span</span>
      <i>斜体</i>
      </body>
      </html>
      
  • 让块级元素水平居中:margin:0 auto;

    div{
    width:100px;
    height:100px;
    background:green;
    margin:0 auto;
    }
    
  • 行高:line-height

image.png

image.png

  • 让文字垂直居中

height的值和line-height的值相等

li{
height:35px;
line-height:35px;
}
  • 边框:border
    • dashed:虚线
    • solid:实线
      <style>
      div{
             width:200px;
             height:200px;
             /* border:2px solid darkturquoise; */
              border:2px dashed darkturquoise; 
         }
      </style>
      

      border-style可能的值

      | 值 | 描述 | | —- | —- | | none | 定义无边框。 | | hidden | 与 “none” 相同。不过应用于表时除外,对于表,hidden 用于解决边框冲突。 | | dotted | 定义点状边框。在大多数浏览器中呈现为实线。 | | dashed | 定义虚线。在大多数浏览器中呈现为实线。 | | solid | 定义实线。 | | double | 定义双线。双线的宽度等于 border-width 的值。 | | groove | 定义 3D 凹槽边框。其效果取决于 border-color 的值。 | | ridge | 定义 3D 垄状边框。其效果取决于 border-color 的值。 | | inset | 定义 3D inset 边框。其效果取决于 border-color 的值。 | | outset | 定义 3D outset 边框。其效果取决于 border-color 的值。 | | inherit | 规定应该从父元素继承边框样式。 |

珠峰动态完整案例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        ul,ol{
            list-style: none;
        }
        a{
            text-decoration: none;
            color:#333;
        }
        body{
            background:lightblue;
        }
        .main{
            width: 500px;
            margin:0 auto;
            border:2px dashed darkcyan;
        }
        h3{
            height: 50px;
            line-height: 50px;
            font-weight: normal;
            font-size:22px;
            text-indent: 30px;
        }
        .more{
            font-size:14px;
        }
        li{
           height: 50px;
           line-height: 50px;
           text-indent: 30px;
        }
        li:hover{
            background:lightseagreen;
        }
        span{
            color:darkcyan;
        }
    </style>
</head>
<body>
    <div class="main">
        <h3>珠峰动态 <a class="more" href="">更多</a></h3>
        <ul>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
            <li>
                <a href=""><span> 珠峰成长的秘密</span>兴盛衰败一挥间,长留慈悲在心念</a>
            </li>
        </ul>
    </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>
    *{
        margin:0 ;padding:0;
    }
    ul,ol{
        list-style: none;
    }
    body{
        background:lemonchiffon;
    }
    a{
        text-decoration: none;
        color:lightgreen;
    }
    li{
        height:35px;
        line-height: 35px;
    }
    .main{
        width:500px;
        margin:0 auto;
        border:1px dashed darkorange;
        padding:20px;
    }
    .icon{
        width:16px;
        height:16px;
        line-height:15px;
        text-align:center;
        background:indianred;
        display:inline-block;
        font-size:12px;
        color:#fff;
    }
    .special{
        color:lightblue;
    }
    </style>
</head>
<body>

    <ul class="main">
        <li>
            <a href="">
                <span class="icon">1</span>
                <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
            </a>
        </li>
        <li>
                <a href="">
                    <span class="icon">1</span>
                    <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                </a>
            </li>
            <li>
                    <a href="">
                        <span class="icon">1</span>
                        <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                    </a>
                </li>
                <li>
                        <a href="">
                            <span class="icon">1</span>
                            <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                        </a>
                    </li>
                    <li>
                            <a href="">
                                <span class="icon">1</span>

                                <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                            </a>
                        </li>
                        <li>
                                <a href="">
                                    <span class="icon">1</span>

                                    <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                                </a>
                            </li>
                            <li>
                                    <a href="">
                                        <span class="icon">1</span>

                                        <span class="special">珠峰就业岁末,</span>珠峰就业还在一直创造奇迹
                                    </a>
                                </li>
    </ul>
</body>
</html>

作业:

1、元素可以划分几类,以及它们各自的特点
2、display 常用的几个值
3、让元素消失的几种方法,及区别
4、常用的样式记会
5、珠峰列表(课堂最后一个案例)敲会
思路不要乱,一个个完成
最后送你们一句话:战胜困难,走出困境,成功就会属于你。

  • 选做:珠峰教学案例

image.png