简体   繁体   English

CSS背景图片有问题

[英]Having trouble with CSS background image

I'm trying to use a stock photo to cover my page. 我正在尝试使用照片作为封面。 For some reason I cannot seem to get this to work. 由于某种原因,我似乎无法使它正常工作。 My image just refuses to cover the page. 我的图像只是拒绝覆盖页面。

 #cover { background-image: url("https://i.stack.imgur.com/QE9pP.jpg"); background-size: cover; background-size: center center; background-repeat: no-repeat; background-attachment: fixed; background-color: #464646; } .cover-content { color: hsla(182, 100%, 28%, 1); font-family: font-family: 'Gravitas One', cursive; font-size: 400%; text-align: center; } 
 <div id="cover"> <div class="cover-content"> <h1>Snowfall Design Studio</h1> </div> </div> 

Your page does not cover the whole viewport. 您的页面未涵盖整个视口。 If you want an image to cover the whole screen, put the background-image on the html or body element 如果要使图像覆盖整个屏幕,请将背景图像放在html或body元素上

 html { height: 100%; } body { min-height: 100%; background-image: url("https://i.stack.imgur.com/QE9pP.jpg"); background-size: cover; background-position: center center; background-repeat: no-repeat; background-attachment: fixed; background-color: #464646; } .cover-content { color: hsla(182, 100%, 28%, 1); font-family: font-family: 'Gravitas One', cursive; font-size: 400%; text-align: center; } 
 <div id="cover"> <div class="cover-content"> <h1>Snowfall Design Studio</h1> </div> </div> 

Here is an example of the image covering the whole page: https://codepen.io/anon/pen/owJVgq 这是覆盖整个页面的图像示例: https : //codepen.io/anon/pen/owJVgq

You needed to move the background images to the body tag and add a viewport of: 您需要将背景图像移至body标签并添加以下视口:

<meta name="viewport" content="width=device-width, initial-scale=1">

If you are looking for this section to be just a section and have more content below the picture, this is what you're looking for: https://codepen.io/anon/pen/BZvbNe 如果您希望本部分只是一个部分,并且在图片下方有更多内容,则是您在寻找的内容: https : //codepen.io/anon/pen/BZvbNe

Again you need to add the viewport, but also add: 同样,您需要添加视口,还需要添加:

body {
  margin: 0px;
  padding: 0px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM