CSS背景

曾经终败给现在 2021-10-19 10:18 548阅读 0赞

背景


































属性 描述
background 简写属性,作用是将背景属性设置在一个声明中。
background-attachment 背景图像是否固定或者随着页面的其余部分滚动。
background-color 设置元素的背景颜色。
background-image 把图像设置为背景。
background-position 设置背景图像的起始位置。
background-repeat 设置背景图像是否及如何重复。

第一个例子

  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> body{
  2. background-color: red
  3. }
  4. div{
  5. widows:50px;
  6. height:50px;
  7. background-color:blue
  8. }
  9. </style>
  10. </head>
  11. <body>
  12. <div> </div>
  13. </body>
  14. </html>

aHR0cHM6Ly93czEuc2luYWltZy5jbi9sYXJnZS8wMDZReW4yUWx5MWc1cHI5OXV3NzZqMzFoYzBtNDB0OS5qcGc

可以看到主体的颜色是red, 其中一部分是blue

第二个例子

  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> body{
  2. /*background-color: red*/
  3. background-image: url("https://wx3.sinaimg.cn/mw690/719f9f6bly1g5p3mpvkxmj21w02ioqv5.jpg");
  4. /*图片居中*/
  5. background-position: center;
  6. /*图片不重复*/
  7. background-repeat: no-repeat;
  8. }
  9. /*div{ widows:50px; height:50px; background-color:blue }*/
  10. </style>
  11. </head>
  12. <body>
  13. <div> </div>
  14. </body>
  15. </html>

aHR0cHM6Ly93czEuc2luYWltZy5jbi9sYXJnZS8wMDZReW4yUWx5MWc1cHJ6ZW93cDRqMzFoYzBvbnFyei5qcGc

可以写成一句话

  1. background: url("https://wx3.sinaimg.cn/mw690/719f9f6bly1g5p3mpvkxmj21w02ioqv5.jpg") center no-repeat

背景属性


































属性 描述
background 简写属性,作用是将背景属性设置在一个声明中。
background-attachment 背景图像是否固定或者随着页面的其余部分滚动。
background-color 设置元素的背景颜色。
background-image 把图像设置为背景。
background-position 设置背景图像的起始位置。
background-repeat 设置背景图像是否及如何重复。

发表评论

表情:
评论列表 (有 0 条评论,548人围观)

还没有评论,来说两句吧...

相关阅读

    相关 css设置背景

    css2设置背景相关属性有如下: background : 简写属性,作用是将背景属性设置在一个声明中。 background-color : 设置元素的背景颜色。