开发者

Align background image counting pixels from the center?

开发者 https://www.devze.com 2023-02-04 15:03 出处:网络
I realized the only way to get a background image properly aligned was counting pixels from the center, since using % and counting pixels from the left sometimes overlays images depending the screen s

I realized the only way to get a background image properly aligned was counting pixels from the center, since using % and counting pixels from the left sometimes overlays images depending the screen size.

There must be a way to align it properly.

Is ther开发者_如何学编程e a way to align the background image horizontally counting pixels from the center?

Thanks


With CSS I would use something like this.

div.background{
    position: absolute; 
    left: 50%; 
    margin-left: -100px;
}

The margin-left would be exactly half of the width of the background.


background-position:center top;
0

精彩评论

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

关注公众号