老生常谈,老手跳过,新手进来。
思路:图片不要设置为div的background,因为你设置了background-size,但是div的height没设置,一样没鸟用,除非你搞个js判断,动态刷新。
换一种思路,直接用显示出来,这样div作为父容器就被你撑大,就不需要div的高度设置了。
然后就看你的图片,如果宽要全部显示,就设置为width:100%,height:auto,反之就设置为width:auto, height:100%.
看代码:
html
<div><img class="fullimg" src="../images/solution/try1001banner.png" /></div>
css
.fullimg{margin:0;padding:0;width:100%;height:auto;}
http://blog.youkuaiyun.com/lanmanck/article/details/53164586
本文介绍了一种使用图片填充HTML div容器的方法,避免了背景图片不适应的问题。通过将图片直接放置于div内并设置img标签的width为100%,height为auto,使得图片能够自动调整大小以完全填充其父容器。
1万+

被折叠的 条评论
为什么被折叠?



