如何居中水平
回答
使用width:100%
絕對div
.home .center {
position: absolute;
bottom: 0;
top:30px;
text-align: center;
width:100%;
}
更新fiddle
我只是忘了「寬度:100%」。非常感謝你:) – MehmetDemiray 2014-09-05 12:14:06
很酷,在這裏完成.. – 2014-09-05 12:21:03
試試這個:
HTML代碼:
<div class="home">
<div class="center">
<a class="arrow fa fa-long-arrow-down fa-3x" href="#"></a>
</div>
</div>
CSS代碼:
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
bottom: 0;
top:30px;
text-align: center;
}
.arrow {
}
'position:fix;'哈??!我想你的意思是'固定'。 – 2014-09-05 10:57:21
。家是相對的。它必須絕對定位。我解決了問題。謝謝 :) – MehmetDemiray 2014-09-05 12:09:08
這應該工作,試試吧。
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: absolute;
margin: 0 auto;
max-width: 960px;
}
.center {
position: relative;
bottom: 0;
top:30px;
text-align: center;
}
.arrow
left: 0;
right: 0;
至於爲什麼它的工作原理的解釋:很好,包裝DIV必須是絕對的,其含量必須是相對於定位是什麼包裝裏面,你please.In這種方式,會更容易如果你要添加的另一個相對的div
這裏工作的例子。您可以刪除.arrow CSS規則,因爲它什麼都不做。
.home {
margin: 0 auto;
height: 100%;
width: 100%;
position: relative;
margin: 0 auto;
max-width: 960px;
}
.home .center {
position: absolute;
width: 100%;
bottom: 0;
top:30px;
text-align: center;
}
我剛剛更改爲您的CSS,它工作正常。
.home {
margin: 0 auto;
}
.home .center {
margin: 0 auto;
text-align: center;
}
.arrow
margin: 0 auto;
}
乾杯!
- 1. 如何水平居中DIV
- 2. 如何水平居中fic?
- 3. 如何水平居中JSpinner
- 4. 水平居中水平ItemsControl
- 5. 水平居中
- 6. 水平居中
- 7. 水平居中UL
- 8. 居中水平UL
- 9. 水平居中水平滾動頁面
- 10. 如何水平居中拖動模式
- 11. 如何居中水平導航欄
- 12. 如何水平居中兩個標籤?
- 13. FXML如何水平居中圖像
- 14. 如何繪製水平線並居中?
- 15. 如何水平和垂直居中div?
- 16. 如何水平居中拆封DIV
- 17. 如何水平居中浮動文字
- 18. 如何垂直和水平居中DIV?
- 19. 如何居中div的水平線?
- 20. 如何水平居中UILabel文本?
- 21. CSS如何水平居中一個div
- 22. CSS如何居中水平菜單?
- 23. 如何將li元素水平居中
- 24. ImageView中水平居中TextView
- 25. 如何將居中的水平recyclerview居中?
- 26. 如何將此div垂直居中以及水平居中?
- 27. 水平居中的錶行
- 28. 水平居中浮動框
- 29. 無法水平居中div
- 30. 水平居中多個UIView
請在問題本身*你的代碼*。的 – gvee 2014-09-05 10:51:24
可能重複[如何垂直居中一個div所有的瀏覽器?(http://stackoverflow.com/questions/396145/how-to-vertically-center-a-div-for-all-browsers) – gvee 2014-09-05 10:52:15
移動'左:0;正確:0;'對絕對定位的父div。 – 2014-09-05 10:53:02