div中图片居中超出后隐藏,center image in div with overflow hidden
2016-05-06 14:21
871 查看
未知图片宽高时
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <style> .pics-container { height: 100px; width: 100px; overflow: hidden; text-align: center; margin: 0 auto; } .pics-container img { height: 100px; min-width: 100%; max-width: none; margin: 0 -100%; } </style> </head> <body> <div class="pics-container"> <!-- 这里有个问题,如果图片是等高宽的话,会等比缩小,看不出hidden的效果 --> <img src="3.png"> </div> </body> </html>
note:这种居中只是相对于水平居中。
已知图片的宽度 ( 400*400)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title>Document</title> 6 <style> 7 .pics-container{ 8 width: 200px; 9 margin: 0 auto; 10 overflow:hidden; 11 position: relative; 12 height: 200px; 13 } 14 .pics-container img { 15 left: 50%; 16 top: 50%; 17 margin-top: -200px; 18 margin-left: -200px; 19 position:absolute; 20 } 21 </style> 22 </head> 23 <body> 24 <div class="pics-container"><img src="3.png" alt="" /></div> 25 </body> 26 </html>
note: 这个居中包含水平和垂直居中,但前提是已知图片的宽高。
未知图片宽高 .listpic { display: table-cell; position: relative; top: -110px; left: 208px; width: 170px; height: 128px; overflow:hidden; text-align: center; vertical-align: middle; } .pic { max-width: 100%; vertical-align: middle; }
参考资料
http://stackoverflow.com/questions/10830735/center-image-in-div-with-overflow-hidden
相关文章推荐
- 添加附件,通过文件管理器
- Picasso创建圆形图像
- ECLIPSE 设置 UTF8
- JS报错,但是语法没有写错
- setContentView()调用SurfaceView布局文件出错的解决方法
- fragment及fragment的通信
- GestureDetector
- Linux SDIO总线驱动(一)
- 调用android系统相机拍照并保存
- Rafy 框架 - 插件级别的扩展点
- NSPredicate 过滤功能
- java线程——多个线程之间切换执行
- PHP自学no00013常量定义取值判定是否已定义
- Android SimpleArrayMap源码解析
- Android 兼容性介绍之setBackground
- python basestring( )
- Android图片加载神器之Fresco-加载图片基础[详细图解Fresco的使用](秒杀imageloader)
- CSS魔法堂:重拾Border之——更广阔的遐想
- Miller Rabin大素数判定+质因子分解 factor
- jenkins使用简记