开发者

CSS background image on DIV's vertical center

开发者 https://www.devze.com 2023-02-26 13:23 出处:网络
I have a div and I need to get a small background image into the vertical cente开发者_如何转开发r of that DIV using CSS.

I have a div and I need to get a small background image into the vertical cente开发者_如何转开发r of that DIV using CSS.

Can anyone help please?

Thanks.


To vertically center:

#con {
    background: url(image.jpg) no-repeat left center;
}

To horizontally center:

#con {
    background: url(image.jpg) no-repeat center top;
}


#somediv {
background: url (image.jpg) no-repeat 50% 50%;
}

the 50% centers it horizontally and vertically.. alternatively you can use center center

0

精彩评论

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