FAQ: Boundaries and Space - Display: Flex

This community-built FAQ covers the “Display: Flex” exercise from the lesson “Boundaries and Space”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Make a Website

FAQs on the exercise Display: Flex

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why does “display: inline” doesn’t horizontally align the images in this exercise?

I was wondering the same thing. Doing this course after the HTML/CSS ones has mostly been review but display: flex; is the first topic that wasn’t covered in the CSS course at all - we only learned about other display values such a inline, block, and inline-block, none of which seem to have any impact on this page when used instead of flex.

I did some experimenting and it looks like the key difference has to do with parent/child element relationships.

HTML:

<!DOCTYPE html>
<html>

<link href="./test.css" type="text/css" rel="stylesheet">

<!--TESTING SPACE-->

<div class="rectangle">
	<p>I'm a rectangle!</p>
</div>
<div class="rectangle">
	<p>So am I!</p>
</div>
<div class="rectangle">
	<p>Me three!</p>
</div>

<div class="parent">
	<p>I'm the first child!</p>
	<p>I'm the second!</p>
	<p>I'm the third!</p>
</div>

<!--TESTING SPACE-->

</html>

CSS:

.rectangle {
	border: 2px solid blue;
	width: 200px;
	height: 300px;
	display: inline-block;
}

.parent {
	margin-top: 10px;
	display: flex;
}

.parent p {
	border: 2px solid red;
	width: 200px;
	height: 300px;
}

Render:

Changing display to flex for the “rectangle” class had no effect, so that tells me that flex is only useful on container elements. On the other hand, changing display to inline-block for the “parent” class created some strange layout changes that I can’t explain.

Hopefully this helps someone!