我想在 div 内的两个按钮之间对齐图片
<div>
<button class="button">left</button>
<div class="picture">
<button class="button">right</button>
</div>
这是我试过的 http://jsfiddle.net/27YPH/
当我为图像使用 img 标签时它有效,但当我使用 css-background 属性设置图像时它变得困惑
图像是 Sprite ,所以我不想使用 img 标签
现在如何将带有背景的 div 放在两个按钮之间?
最佳答案
您的代码不正确。您没有 <div class="picture">
的结束 div
您需要在 <div class="picture"> </div>
之前关闭它
在那之后,你需要放一个height
和 width
对于包含背景图像的类。
例如,
.picture
{
float:left;
background:url("http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png") 0 0;
width:128px; height:128px;
}
然后,您可以对齐图像。
下面是演示。
希望这对您有所帮助。
添加:
如果你想垂直对齐你的图像,根据你的代码,下面是演示。
关于html - div 与 css 背景的水平对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19630428/