我嘗試水平居中2個divs並對齊它們之間的這2個div。當我在每個div中放入不同大小的文本時,問題就來了。以下是示例:http://jsfiddle.net/DgEcs/1/中心2文本與文本
爲什麼紅色的div會向下移動以及如何解決?
CSS:
.container{
margin: 20px auto;
height: 50px; line-height: 50px;
text-align: center; /* to center red and blue */
background: whiteSmoke;
}
.red{
display:inline-block; /* to put it side by side */
font-size: 10px;
background:red;
}
.blue{
display:inline-block; /* to put it side by side */
font-size: 26px;
background:blue;
}
HTML:
<div class="container" >
<div class="red"> aaaaaaa </div>
<div class="blue"> bbbbbbb </div>
</div>
好,它的工作原理。你知道爲什麼會發生?我之前嘗試過:vertical-align:center;它不起作用,你明白爲什麼嗎? – Nrc 2013-04-10 14:06:32