Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop an image displaying outside of the div

Tags:

html

css

Consider this code...

<div id="outer" style="position:absolute;width:100px;height:100px;border:1px solid black">   <div id="inner">     <img src="http://rabbitempire.org/wp-content/uploads/Pet-Rabbit-Facts.jpg">   </div> </div> 

What style(s) do I need to add to make it so only the top left hand corner of the image is visible?

Please note, I don;t want to use a background image because the question is really about divs, believe it or not but the rabbit isn't part of my application. Oh and in "real life" I wouldn't use inline css.

like image 812
thomas-peter Avatar asked Jul 30 '12 17:07

thomas-peter


People also ask

How do I stop an image from getting in a div?

Try giving an overflow:hidden to the div. Show activity on this post. add overflow:hidden; to your div style. Show activity on this post.

How do I make an image fit in a div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.


2 Answers

div#outer { overflow:hidden; }​ 

demo here: http://jsfiddle.net/J34aJ/

like image 66
Colin Brock Avatar answered Sep 18 '22 23:09

Colin Brock


You can just apply img { max-width: 100%; height: auto; } to image tag

like image 25
Sann Min Win Avatar answered Sep 18 '22 23:09

Sann Min Win