In this activity, youβll practice aligning CSS Flexbox items inside parent containers.
Open the file index.html
.
When you open it in your browser, take notice of what itβs missing.
Open the index.css
file and add the align-items property
to the .alignItems
selector.
Set the value for align-items
property to center.
Save your files and refresh index.html
in your browser.
Change the value for align-items
to flex-end
or flex-start
to see the differences that each value creates.
Add the justify-content
property to the .justifyContent
selector.
Lastly, add properties to the .perfectlyCentered
selector to center the child element.
align-items
and justify-content
.Your finished design should look like the image below:
align-items
and justify-content
.02-Stu-Aligning-With-Flex-Items
βββ css
β βββ index.css
βββ index.html
<!DOCTYPE html>
<html lang="en-gb">
<head>
<link href="css/index.css" type="text/css" rel="stylesheet">
</head>
<body>
<section class="alignItems flexContainer">
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</section>
<section class="justifyContent flexContainer">
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</div>
</section>
<section class="perfectlyCentered flexContainer">
<div class="flexItem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</section>
</div>
</body>
</html>
.flexItem {
background-color: lightyellow;
margin: 10px;
padding: 10px;
width: 250px;
height: 250px;
}
.flexContainer {
display: flex;
height: 400px;
background-color: lightblue;
margin: 10px;
padding: 10px;
}
.justifyContent {
justify-content: center;
}
.perfectlyCentered {
justify-content: center;
align-items: center;
}
.alignItems {
align-items: center;
}