Avoid an image to go outside a div?

六眼飞鱼酱① 提交于 2019-12-10 13:06:15

问题


I have:

<div style="height:15px">
    <img src="image" />
</div>

The image is bigger than 15px, so it's outside the div when you see it. How do I "crop" the image (show only the 15px port of it), only using css?


回答1:


You need overflow:hidden see an example here:

http://www.jsfiddle.net/S8qAq/

Read about overflow: here W3Schools

Good luck!




回答2:


Try giving an overflow:hidden to the div.




回答3:


add overflow:hidden; to your div style.




回答4:


Use the overflow css property:

overflow: hidden;



回答5:


use

overflow:hidden;



回答6:


I am surprised no one has suggested object-fit: cover;



来源:https://stackoverflow.com/questions/4328625/avoid-an-image-to-go-outside-a-div

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!