简体   繁体   中英

How to make background image not resizable in html?

body {
    background: url('../../asset/background.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

This is my code for an background image. I want the image to be not resizable when I am resizing the browser.

You shouldn't use background-size:cover; . With that CSS you're telling the browser you want the background image to expand to cover the whole background area.

If you want the background image centered and not resized, just do this:

body {
    background: url('../../asset/background.jpg') no-repeat center center;
}

You can position the background in any manner you like, here are more options .

尝试设置背景大小:

background-size: 100px 100px;

Setting the background-size to cover occupies the space of the div. See this .

Remove the background-size property and it will work fine.

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