有沒有辦法讓我的瀏覽器中心的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. 如何浮動div垂直中心對齊在另一個div
- 3. CSS中心垂直對齊div
- 4. 如何垂直對齊div?
- 5. 如何垂直對齊div?
- 6. 如何垂直對齊div中的div?
- 7. 如何在中間垂直對齊div?
- 8. 中心垂直對齊
- 9. npoi垂直對齊中心
- 10. 垂直對齊div
- 11. 垂直對齊DIV
- 12. HTML:在div中垂直對齊div
- 13. 在父div中垂直對齊div?
- 14. 如何垂直對齊父div的中心
- 15. 如何使中心垂直和水平對齊div?
- 16. 如何對齊DIV垂直和水平中心
- 17. 垂直對齊絕對div
- 18. 在垂直中心對齊圖像
- 19. 如何將文字的垂直中心與圖像的垂直中心對齊?
- 20. 在div列中垂直對齊文本中心bootstrap
- 21. 文本左對齊和垂直中心div div
- 22. 對齊的DIV子的div內容垂直排列中心
- 23. 如何垂直對齊Div的元素
- 24. 如何垂直對齊div文本?
- 25. 如何垂直對齊DIV與圖像
- 26. 如何垂直對齊的div文字
- 27. 如何垂直對齊這2個div?
- 28. Flo div垂直對齊
- 29. 垂直對齊文本div
- 30. img垂直對齊格div
這,我的朋友,這是最好的JavaScript/jQuery的解決而不是純粹的CSS的老問題,沒有防彈,100%乾淨CSS解決方案這也適用於每個瀏覽器。然而,JavaScript使得這很簡單。你應該考慮。 –