2012-05-03 70 views
1

我無法獲得一個較小的(上標)行內元素與另一個行內元素對齊。CSS無法垂直排列元素

基本上em元素(包含單詞'USD')應該與內嵌文本(包含單詞ABC)對齊,因此這兩個單詞的頂部位於同一行上。

對於我來說,下面我的代碼中,USD字樣是一半,即使我將行高設置爲35px;

任何想法我做錯了什麼?

謝謝,

克里斯

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<style type="text/css"> 
.plan-types-pricing 
{ 
    font-size: 35px; 
    line-height: 35px; 
} 

.plan-types-pricing strong 
{ 
    display: block; 
} 

.plan-types-pricing em 
{ 
    font-size:12px; 
    vertical-align: top; 
    line-height: 35px; 
} 

.plan-types-pricing small 
{ 
    font-size: 12px; 
    vertical-align: baseline; 
} 

</style> 
</head> 
<body> 
    <span class="plan-types-pricing"> 
     <strong>Starting at</strong> 
     <em>USD</em> 
     ABC 
     <small>/month</small> 
    </span> 
</body> 
</html> 
+0

你能不能請這個 – RSM

+0

嘗試line-height:50px;在em裏面... –

回答

1

.plan-types-pricing em行高應所需的高度 - 字體大小(35 - 12 = 23) 所以設置的emline-height23px

.plan-types-pricing em 
{ 
    line-height: 23px; 
    font-size: 12px; 
    vertical-align: top; 
}