在下面HTML,爲什麼所有的內容出現在<footer>
之外,爲什麼不垂直方向的中間對齊的文本?垂直對齊文本使用CSS
<html>
<head>
<style>
body {
margin-left: 20%;
margin-right: 20%;
}
footer {
text-align: center;
border: 1px dotted black;
}
#foo {
float: left;
vertical-align: middle;
}
#bar {
float: right;
}
</style>
</head>
<body>
<footer> <span id="foo">this is some text</span>
<span id="bar"><img src="http://i.imgur.com/wgFpmlN.png"></span>
</footer>
</body>
</html>
使用'線height'財產。嘗試設置其值等於頁腳高度。它只適用於內聯元素,對於需要使用邊距播放的塊元素。 –
這可能是有用的http://deeson-online.co.uk/labs/how-centre-align-text-or-content-vertically-css – zdesam
如果因爲某些原因,「行高」不是一個選項(垂直由該高度創建的空間不是可選的),使用'padding'作爲元素。另外定義元素的「高度」。只要記住將其設置爲「display:block」或「display:inline-block」即可 –