博客列表 >css-20201217css03(伪类选择器状态、css优先级,css背景图片,盒子模型初步)

css-20201217css03(伪类选择器状态、css优先级,css背景图片,盒子模型初步)

CC
CC原创
2020年12月18日 20:28:51495浏览

伪类状态与选择器优先级

  • 一般状态
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>伪类选择器:状态匹配</title>
  7. <link rel="stylesheet" href="css01.css">
  8. </head>
  9. <body>
  10. <a href="https://www.php.cn/">php中文网</a>
  11. </body>
  12. </html>

01 默认状态

  1. a:link {
  2. color: aqua;
  3. text-decoration: none;
  4. }

02已访问状态

  1. a:link {
  2. color: aqua;
  3. text-decoration: none;
  4. }
  5. a:visited{
  6. color: bisque;
  7. }

03悬停状态

  1. a:link {
  2. color: aqua;
  3. text-decoration: none;
  4. }
  5. a:hover{
  6. color: hsl(0, 75%, 49%);
  7. text-decoration: underline;
  8. }

04 激活状态

  1. a:link {
  2. color: aqua;
  3. text-decoration: none;
  4. }
  5. a:active{
  6. color: blue;
  7. }

选择器优先级

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <link rel="stylesheet" href="css01.css">
  8. </head>
  9. <body>
  10. <h2>hello</h2>
  11. </body>
  12. </html>
  • 选择器相同,与顺序有管
  1. h2 {
  2. color: #d3d62b;
  3. }
  4. h2 {color: rgb(25, 211, 25);
  5. }
  • 类选择器大于标签选择器(id>class>tag)
  1. h2 {
  2. color: #d3d62b;
  3. }
  4. h2 {color: rgb(25, 211, 25);
  5. }
  6. .on {
  7. color: rgb(228, 40, 65);
  8. }
  • css优先级

    [id,css,tag]

  1. h2 {
  2. color: #d3d62b;
  3. }
  4. body h2 {color: rgb(25, 211, 25);
  5. }
  6. html body h2 {
  7. color: rgb(228, 40, 65);
  8. }
  1. /* [0,1,0] */
  2. .on {
  3. color: #d3d62b;
  4. }
  5. /* [0.1,1] */
  6. h2.on {color: rgb(25, 211, 25);
  7. }
  8. /* [0,0,3] */
  9. html body h2 {
  10. color: rgb(228, 40, 65);
  11. }
  • 字体属性
  1. /* 属性写法 */
  2. .on {
  3. font-family: sans-serif;
  4. font-size: 26px;
  5. }
  6. /* 简写 */
  7. h2.on {
  8. font: italic lighter 36px sans-serif;
  9. }

导入图片

  1. body {
  2. background-color: cornflowerblue;
  3. background-image:url('https://img.php.cn/upload/course/000/000/001/5fae4f08a043a576.png') ;
  4. /* 图片不重复 */
  5. background-repeat: no-repeat;
  6. /* 图片尺寸 */
  7. background-size: 300px;
  8. /* 图片位置 */
  9. background-position: top;
  10. }

盒子模型

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box {
  9. /* 盒子尺寸 */
  10. width: 200px;
  11. height: 200px;
  12. background-color: chartreuse;
  13. box-sizing: border-box;
  14. }
  15. .box {
  16. /* 边框 */
  17. border-top: crimson solid 10px;
  18. /* 边距 */
  19. border: cyan solid 10px;
  20. /* 内边距 */
  21. padding: 10px;
  22. /* 外边距 */
  23. margin: 5px;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="box"></div>
  29. </body>
  30. </html>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议