我有一个 200 x 200 像素的 div。我想在 div 的中间放置一个 50 x 50 px 的图像。
如何做呢?
我可以通过使用text-align: centerdiv 使其水平居中。但是垂直对齐是问题..
text-align: center
就个人而言,我会将它作为 div 中的背景图像,其中的 CSS 是:
#demo { background: url(bg_apple_little.gif) no-repeat center center; height: 200px; width: 200px; }
id="demo"(假设您已经指定了 divheight并width添加 abackground不应该是问题)
id="demo"
height
width
background
让浏览器承受压力。