【发布时间】:2012-02-16 15:19:13
【问题描述】:
我正在尝试使用 CSS 设置一些按钮的样式,并且我的按钮容器是一个内联块,其中文本使用行高在块内垂直居中。问题是当我使用另一个内联块向按钮添加图标时,它似乎调整了前面文本的垂直对齐方式,尽管图标在中间正确对齐。
<style>
.button {
background: #ccc;
display: inline-block;
padding: 6px 6px 5px 6px;
line-height: 16px;
height: 16px;
position: relative;
vertical-align: text-bottom;
}
.button .icon {
background-image: url("../images/button-down.png");
display: inline-block;
height: 16px;
width: 16px;
margin: 0;
text-indent: -99999px;
overflow: hidden;
background-repeat: no-repeat;
position: relative;
}
</style>
<!-- with icon -->
<a href="#" class="button">Save <span class="icon"></span></a>
<!-- without icon -->
<a href="#" class="button">Save</a>
当图标出现时,文本会向下移动。我可以帮助我理解为什么图标块会影响前面文本的位置。
【问题讨论】: