From the course: CSS: Images
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Fitting an image inside flexbox
From the course: CSS: Images
Fitting an image inside flexbox
- Fitting images inside flexible boxes or flex box or display flex boxes works a little bit differently from what we've looked at previously. So let's take a closer look at flex in particular. This example is the same example we used for grid. I have four images with different proportions, different heights and different widths and I'm going to display them this time in a horizontal line of four images. To do that, I'll first grab the content container, that's the one that wraps around everything and set its display to flex. This creates a flexible box that flexes based on the intrinsic size of its elements. And as a result we get horizontal scrolling because these images are huge. To fix that, I need to go into the individual images and set their width because that way the flexible box will scale to their width. And that means if I want to fit four across the view port, I need to set their width to 25%. That will give me…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Modern image markup5m 55s
-
(Locked)
Getting rid of the space underneath an image4m 3s
-
(Locked)
Fitting an image inside any container5m 45s
-
(Locked)
Create a square (or other proportion) image5m 48s
-
(Locked)
Position an image inside a container3m 4s
-
(Locked)
Use CSS to crop an image3m 18s
-
(Locked)
Fitting an image inside a grid cell3m 8s
-
(Locked)
Fitting an image inside flexbox4m 38s
-
(Locked)
Fitting background images to any container2m 33s
-
(Locked)
Position background image within a container4m 55s
-
-
-
-
-