居中背景圖片?
回答
您必須將html
元素的高度設置爲100%
才能使您的代碼正常工作。目前,您的身體的偏移高度爲0px。
html, body {
height: 100%;
}
爲未來的讀者:要居中的背景下,使用方法:
background-position: center center;
爲了保持背景在相同的位置,當用戶滾動,使用:
background-attachment: fixed;
見this page爲一個完整的參考。
設置background-position: 50% 50%
並在html
元素上設置height: 100%
。高度是必不可少的,否則,背景會集中在錯誤的空間中。
除非你已經使用了100%的高度,在這種情況下,你不應該對'html'做任何改變,因爲你可能使用'min-height'。 –
當然是的,但在這個特定的情況下,高度沒有指定,這就是它不起作用的原因。您可以打開該網站並在FireBug中修改樣式,以查看'html'上的高度是這裏缺少的唯一東西。 – GolezTrol
我說這是爲了參考未來的遊客。 –
- 1. 在Android中居中背景圖片
- 2. 使背景圖片居中鏈接
- 3. CSS - 居中頁腳背景圖片
- 4. 在背景圖片上居中文字
- 5. 大型居中背景圖片
- 6. 背景圖片
- 7. 背景圖片
- 8. h標籤在IE瀏覽器中居中的背景圖片
- 9. 背景圖片上的背景圖像
- 10. 在DIV中居中背景圖像
- 11. 在兩列左側居中放置一個背景圖片
- 12. 旋轉(改變),居中,拉伸背景圖片腳本
- 13. 居中背景Jumbotron圖片,並使其移動響應
- 14. JToolBar中的背景圖片
- 15. div中的背景圖片
- 16. JFrame中的背景圖片
- 17. Jumbotron背景圖片
- 18. Android:背景圖片
- 19. UITableViewController背景圖片
- 20. Actionbarsherlock背景圖片
- 21. AQGridView背景圖片
- 22. UIProgressView背景圖片
- 23. ImageMagick背景圖片?
- 24. JOptionPane背景圖片
- 25. GWT背景圖片
- 26. iframe背景圖片
- 27. createElement背景圖片
- 28. AndEngine背景圖片
- 29. Silverlight背景圖片
- 30. QLineEdit背景圖片
無代碼 - 只是一個鏈接 - 窮人! –
鏈接說這一切,在這種情況下。不過,jsfiddle會更好。 – GolezTrol