【发布时间】:2011-06-23 17:57:39
【问题描述】:
我知道这是一个相当简单的问题,但我终其一生都无法弄清楚。我有两个已应用背景图像的链接。这是它目前的样子(为阴影道歉,只是一个按钮的粗略草图):
但是,我希望这两个按钮并排放置。我真的无法弄清楚对齐需要做什么。
这是 HTML
<div id="dB"}>
<a href="http://notareallink.com" title="Download" id="buyButton">Download</a>
</div>
<div id="gB">
<a href="#" title="Gallery" onclick="$j('#galleryDiv').toggle('slow');return false;" id="galleryButton">Gallery</a>
</div>
这是 CSS
#buyButton {
background: url("assets/buy.png") 0 0 no-repeat;
display:block;
height:80px;
width:232px;
text-indent:-9999px;
}
#buyButton:hover{
width: 232px;
height: 80px;
background-position: -232px 0;
}
#buyButton:active {
width: 232px;
height: 80px;
background-position: -464px 0;
}
#galleryButton {
background: url("images/galleryButton.png") 0 0 no-repeat;
display:block;
height:80px;
width:230px;
text-indent:-9999px;
}
#galleryButton:hover{
width: 230px;
height: 80px;
background-position: -230px 0;
}
#galleryButton:active {
width: 230px;
height: 80px;
background-position: -460px 0;
}
【问题讨论】:
-
光看标题首先想到的是
float:left; -
@JCOC611:将
float:left;应用到divs 上做得很好。您可以发表您的评论作为答案吗?谢谢! -
第二个是
display: inline-block;,但它的支持不太好...... -
float:left inside a container 可以工作,但我会尝试使用两个 标签而不是s 作为按钮。如前所述,添加 float: left;到 #buyButton 和 #galleryButton,然后添加另一个元素 clear: both;清除浮动。为什么使用 div(块元素)来包装 ?