CSS 背景图像显示不正确

问题描述 投票:0回答:1

我试图在网页上显示背景图像,它显示图像底部的三分之二,然后是顶部的三分之一。

这不是.jpg文件的问题;我尝试了完全不同的图像,相同的症状。

我已将其归结为最小的测试用例,仅显示图像而没有其他内容。浏览器是 Windows 11 上最新版本的 Chrome。

如果我将

cover
替换为
contain
100% 100%
,图像会完全消失。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Test</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      background-image: url('https://picsum.photos/1920/1080');
      background-size: cover;
      background-position: center;
    }
  </style>
</head>

<body>
</body>

</html>

html css background-image
1个回答
0
投票

如果你想显示全高、全宽且不重复的背景图像,请尝试将其添加到正文样式中:

  height: 100vh;
  width: 100vw;
  background-repeat: no-repeat;
© www.soinside.com 2019 - 2024. All rights reserved.