简体   繁体   中英

body {background: url(image.png)} won't center or adapt to navigator size?

So I have a basic school project and a samll bug is really annoying me... been at it for a few hours nows..

I need a background that looks like this: 在此处输入图像描述

It is specified that I must add the background image to my body element, so here is what I did in my CSS stylesheet:

body {
background: no-repeat url(background.jpg);
background-position: center center;
background-color: #f2f2f2; }

All the other rules you see were specified by the teacher. Here is what it gives on Firefox: 在此处输入图像描述

First off it's too large for the navigator compared to the background image in the teachers example. Second it isn't centered..

Any kind of help would be much appreciated:)

I Think what is missing is:

 body { background: no-repeat url(background.jpg); background-size: cover; background-attachment: fixed; background-position: center center; background-color: #f2f2f2; }

The background-attachment property sets whether a background image scrolls with the rest of the page, or is fixed. and the background-size property specifies the size of the background images, cover Resize the background image to cover the entire container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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