HTML Code:
<!DOCTYPE html><!-- Define document type as HTML -->
<html><!-- Begin HTML document -->
<head><!-- Start of document header -->
<title>How to align the items of the flexible element</title><!-- Title of the HTML page -->
<style>/*-- Begin CSS styling */
#xyz {
/* CSS rule for the element with id "xyz" */
width: 80px;
/* Set the width of the element to 80 pixels */
height: 250px;
/* Set the height of the element to 250 pixels */
border: 1px solid #3300FF;
/* Add a 1 pixel solid border with color #3300FF */
display: -webkit-flex; /* Safari */
/* Use flexbox layout for Safari browsers */
-webkit-flex-flow: row wrap; /* Safari 6.1+ */
/* Set flex direction to row and allow wrapping for Safari */
-webkit-align-content: space-around; /* Safari 7.0+ */
/* Align content evenly with space around for Safari */
display: flex;
/* Use flexbox layout for other browsers */
flex-flow: row wrap;
/* Set flex direction to row and allow wrapping for other browsers */
align-content: space-around;
/* Align content evenly with space around for other browsers */
}
#xyz div {
/* CSS rule for div elements inside the element with id "xyz" */
width: 80px;
/* Set the width of the div elements to 80 pixels */
height: 80px;
/* Set the height of the div elements to 80 pixels */
}
</style><!-- End CSS Styling -->
</head><!-- End of document header -->
<body><!-- Start of document body -->
<div id="xyz"><!-- Start of div with id "xyz" -->
<div style="background-color:#CCCC66;"></div><!-- First nested div with background color -->
<div style="background-color:#CC66CC;"></div><!-- Second nested div with background color -->
<div style="background-color:#FF99CC;"></div><!-- Third nested div with background color -->
</div><!-- End of div with id "xyz" -->
</body><!-- End of document body -->
</html><!-- End of HTML document -->
Explanation:
Live Demo:
See the Pen align-content-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4