桌面版看起来不错,但移动版剪裁了背景。我的意思是,当我滚动它时,它具有两个背景的效果。
不知道是css
还是html
文件有问题
body, html{
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<!-- Required meta tags -->
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://use.fontawesome.com/releases/v5.0.6/js/all.js">
</script>
<link href="https://fonts.googleapis.com/css family=Montserrat:300,600,700i" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>
最佳答案
因为您为两个元素(html 和 body)设置了背景图像。像这样的简单网页布局:
<html>
<head>
</head>
<body>
</body>
</html>
您可以更改 body
的 height
值,但不能更改 html
! HTML 的高度值始终是自动的。因此,向下滚动1080px后,body背景结束,显示html背景。要解决这个问题,只需将背景添加到主体并删除高度值即可。
body{
margin: 0;
padding: 0;
background-image: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
关于html - 我的网站背景有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964056/