我網站上的徽標文本出於某種原因不在本地。通過關閉display: inline-block
,我可以使其重新居中。但是,這會使文本週圍的間距變得平坦,並且我無法將間距重新放回文本之上(無法對內聯元素執行垂直填充)。
我如何能夠使文字與背景顏色居中? (嘗試添加text-align: center
在Chrome開發工具自動評分因故?使用顯示器內嵌塊時文字偏離中心
HTML
<h1 class="logo">
<a href="/"><span class="text logo-title">SomeLogoText</span></a>
</h1>
以下(CSS)
h1.logo {
font-family: "Roboto Slab", arial, sans-serif;
margin-top: 0;
margin-bottom: 0;
font-weight: bold;
font-size: 15px;
float: left;
a {
color: #fff;
padding: 15px 30px;
display: inline-block;
text-align: center;
line-height: 1.4;
max-width: 155px;
background: @color;
.border-radiuses(0, 4px, 4px, 0);
.transition (color 0.4s ease-in-out);
position: relative;
font-size: 20px;
&:hover {
text-decoration: none;
}
}
.logo-title {
vertical-align: middle;
line-height: 1.6;
}
}
感謝您解釋得非常好。這是一個很大的幫助 – Yunti