且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使图像中心(垂直和水平)在一个更大的div

更新时间:2021-10-13 21:45:20

就个人而言,我将它放置为div中的背景图像,CSS因为:

Personally, I'd place it as the background image within the div, the CSS for that being:

#demo {
    background: url(bg_apple_little.gif) no - repeat center center;
    height: 200px;
    width: 200px;
}

(假设有 id =demo $ c>和已经指定高度 不应该是问题)

(Assumes a div with id="demo" as you are already specifying height and width adding a background shouldn't be an issue)

让浏览器解决紧张。