Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid an image to go outside a div?

Tags:

html

css

crop

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?

like image 594
Somebody still uses you MS-DOS Avatar asked Dec 01 '10 20:12

Somebody still uses you MS-DOS


People also ask

How do you keep something from going out of divs?

you need to add a min-width to your image. flex needs this for whatever reason, otherwise it will not downscale the elements.

How do I control an image 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.

How do I hide overflow photos?

To activate the overflow property enclose the image, within a div of a particular width and height, and set overflow:hidden . This will ensure that the base container will retain its structure, and any image overflow will be hidden behind the container.


2 Answers

You need overflow:hidden see an example here:

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

Read about overflow: here W3Schools

Good luck!

like image 51
Trufa Avatar answered Sep 19 '22 11:09

Trufa


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

like image 34
Javaish Avatar answered Sep 22 '22 11:09

Javaish