开发者

Centering a background image? [closed]

开发者 https://www.devze.com 2023-04-05 18:18 出处:网络
开发者_StackOverflow This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is
开发者_StackOverflow This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

I am failing to see why I can't get my background image to be positioned center center.

Help?


Set background-position: 50% 50% and set the height: 100% on the html element. The height is essential, otherwise, the background gets centered in the wrong space.


You have to set the height of the html element to 100% in order to get your code to work. Currently, your body has an offset height of 0px.

html, body {
    height: 100%;
}

To future readers: To center a background, use:
background-position: center center;

To keep the background at the same position when a user scrolls, use:
background-attachment: fixed;

See this page for a full reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消