有沒有辦法讓我的瀏覽器中心的div verticaly與CSS的用法對齊?如何在中心對齊垂直div?
1
A
回答
1
下面是做這件事:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
html {
display: table;
width: 100%;
height: 100%
}
body {
display: table-row;
margin: 0;
height: 100%
}
#foo {
display: table-cell;
height: 100%;
vertical-align: middle
}
#test {
margin: auto;
background-color: #ccc
}
</style>
</head>
<body>
<div id="foo">
<div id="test">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
</body>
</html>
+1
我不喜歡你需要更多元素的事實。 –
+0
這是最好的解決方案! :) 非常感謝Shadow2531! –
+0
display:table-cell - 不能在ie7及以下版本中工作。 – anglimasS
相關問題
- 1. 垂直對齊div中的中心
- 2. CSS中心垂直對齊div
- 3. npoi垂直對齊中心
- 4. 中心垂直對齊
- 5. 垂直對齊DIV
- 6. 垂直對齊div
- 7. HTML:在div中垂直對齊div
- 8. 在父div中垂直對齊div?
- 9. 如何對齊DIV垂直和水平中心
- 10. 在垂直中心對齊圖像
- 11. 文本左對齊和垂直中心div div
- 12. 如何垂直對齊這2個div?
- 13. 對齊兩個div垂直
- 14. 始終垂直對齊DIV
- 15. 垂直對齊div(無表)
- 16. html div垂直對齊
- 17. 垂直對齊浮動div
- 18. 垂直對齊div中的div
- 19. 在div中垂直對齊li項目
- 20. 在div中垂直對齊文本
- 21. 在DIV標記中的垂直對齊
- 22. 在引導列中垂直對齊div
- 23. 不能在div中垂直對齊
- 24. 垂直中心div
- 25. CSS垂直對齊圓圈中心
- 26. Bootstrap col-md-6對齊垂直中心
- 27. 如何將此垂直對齊的div對齊到右側?
- 28. 垂直對齊固定大小的中心圖像div
- 29. 垂直對齊文本在流體div
- 30. 中間垂直對齊內嵌塊div
這,我的朋友,這是最好的JavaScript/jQuery的解決而不是純粹的CSS的老問題,沒有防彈,100%乾淨CSS解決方案這也適用於每個瀏覽器。然而,JavaScript使得這很簡單。你應該考慮。 –