我的网站背景出现问题

时间:2018-12-28 20:40:12

标签: html css

桌面版本看起来不错,但是移动版本正在削减背景。我的意思是,当我滚动时,它具有两个背景。

我不知道问题出在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>

3 个答案:

答案 0 :(得分:1)

因为您为两个元素(html和body)设置了背景图像。这样的简单网页布局:

<html>
  <head>
  </head>
  <body>
  </body>
</html>

您可以更改height的{​​{1}}值,但不能更改body! HTML的高度值始终是自动的。因此,向下滚动1080px后,主体背景结束并显示html背景。要解决此问题,只需将背景添加到主体并删除高度值。

html

答案 1 :(得分:0)

添加此媒体代码

@media screen and (max-width:500px){
  body, html {
    background-size:100% 100%;
  }
}

答案 2 :(得分:0)

您无需为html和body设置bckgound。仅设置正文的背景。

body{ /* Remove html from this lie */
height: 1080px;
margin: 0;
padding: 0;
background: url("img/Mountain.jpg");
background-size: cover;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
}
相关问题