我有以下HTML:
<span id="ctl00_smpWeb" class="breadcrumb hidOverflow">
<span>
<a href="default.aspx" title="Home">
<img src="umb.png" alt="Home" title="Home" class="home" style="vertical-align: middle;" />
</a>
</span>
<span></span>
<span>Services</span>
</span>
CSS:
.breadcrumb {
font: 9px 'Verdana', 'Graduate', 'Arial', 'Helvetica', 'sans-serif';
height: 30px;
color: #9b9b9b;
width: 100%;
font-weight: bold;
}
.hidOverflow {
overflow: hidden;
}
输出:
主页图标不是在两条橙色线之间垂直居中,而文本是。
请帮助居中。
如果我从图像中删除垂直对齐,则会发生这种情况:
答案 0 :(得分:4)
为您的图片设置display:inline-block
和vertical-align:middle
,请参阅下面的代码段:
.breadcrumb {
font: 9px'Verdana', 'Graduate', 'Arial', 'Helvetica', 'sans-serif';
height: 30px;
color: #9b9b9b;
width: 100%;
font-weight: bold;
}
.hidOverflow {
overflow: hidden;
}
.home {
display: inline-block;
vertical-align: middle
}
a {
text-decoration: none;
/* just for demo */
}
&#13;
<span id="ctl00_smpWeb" class="breadcrumb hidOverflow">
<span>
<a href="default.aspx" title="Home">
<img src="http://placehold.it/100x100&text=home" alt="Home" title="Home" class="home" />
</a>
</span>
<span></span>
<span>Services</span>
</span>
&#13;