我有width:100%
和overflow:hidden
我需要放置的2500-3000px
它裏面的圖像的父股利,但具有圖像水平方向上居中(裁剪左側和右側),以使主中心部的圖像顯示在較小的屏幕上,但沒有水平滾動條。
我不能使用background-image
,因爲圖像是通過php動態添加的。
請幫忙。中心圖像水平內溢出:隱藏的div
6
A
回答
10
如果您知道圖像的寬度和高度事先(即它們都是一樣的),那麼你可以使用舊margin
/position
招:
#myImage {
height: the image's height;
left: 50%;
margin-left: -half the image's width;
margin-top: -half the image's height;
position: relative;
top: 50%;
width: the image's width;
}
0
說myImg.jpg是100x100px:
<div style="overflow:hidden; width:100%;">
<img src="myImg.jpg" style="left: 50%; top:50%; position:relative; margin:-50px 0 0 -50px; width:100px; height:100px;" />
</div>
1
CSS:
div {background:salmon; width:100%; height:200px; overflow:hidden;}
img {left: 50%; margin-left:-1500px; position:relative;}
HTML:
<div><img src="" /></div>
相關問題
- 1. 水平展開DIV不溢出:隱藏
- 2. 使圖像div水平溢出父div
- 3. div中溢出隱藏的中心圖像
- 4. 隱藏html分區的水平溢出
- 5. 保持圖像水平流動,隱藏溢出
- 6. 隱藏水平CSS菜單溢出
- 7. Html/CSS隱藏水平溢出
- 8. 溢出:隱藏只能水平工作
- 9. 中心李水平與內溢出的div:汽車
- 10. DIV內有溢出的DIV:隱藏?
- 11. 畫布圖像:中心寬圖像並隱藏溢出
- 12. 滾動div內隱藏溢出div
- 13. 圖像沒有溢出隱藏:隱藏
- 14. 如何強制溢出:隱藏分區圖像內的div?
- 15. 圖像不溢出:隱藏
- 16. 允許垂直溢出,同時隱藏水平溢出
- 17. 顯示DIV內容與溢出隱藏
- 18. 溢出:隱藏移動div內
- 19. 中心的圖像水平
- 20. 允許圖像在div中水平溢出
- 21. 如何在隱藏溢出的div中顯示圖像?
- 22. 中心圖像垂直分區與溢出隱藏
- 23. 水平滾動溢出圖像 - HTML/CSS
- 24. 水平滾動圖像溢出問題
- 25. 水平中心div
- 26. 中心DIV水平
- 27. 溢出隱藏我的圖像
- 28. KineticJS:隱藏溢出圖層的內容
- 29. 在具有隱藏溢出的中心特定li div
- 30. 中心div裏面的包裝溢出隱藏