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.
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.
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.
div#outer { overflow:hidden; }
demo here: http://jsfiddle.net/J34aJ/
You can just apply img { max-width: 100%; height: auto; }
to image tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With