整个页面的背景图片

丹尼尔

我希望图片成为整个页面的背景。

另一个问题是,使用 no-repeat 属性,照片会消失

有人可以写背景属性来设置吗?

<!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;
    }
    
    body {
      width: 100%;
      height: 300vh;
    }
    
    body::after {
      content: '';
      background-image: url('https://upload.wikimedia.org/wikipedia/commons/d/d0/Background-clouds.jpg');
      position: fixed;
      top: 0;
      left: 0;
      min-width: 100%;
      min-height: 100%;
    }
  </style>
</head>
<body>
</body>
</html>

雅利安 Twanju |

使用背景重复属性,添加background-size: cover;属性。

检查下面的css规则。

body::after {
  content: '';
  background-image: url('https://upload.wikimedia.org/wikipedia/commons/d/d0/Background-clouds.jpg');
  position: fixed;
  top: 0;
  left: 0;
  min-width: 100%;
  min-height: 100%;
  background-repeat: no-repeat;
  background-size: cover;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章