Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![gary peart](https://secure.gravatar.com/avatar/efb497ca8d225dc1ef890edccdd2efde?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
gary peart
6,496 PointsFlexbox - Is this example I've done a valid layout?
Hi,
I'm trying not to confuse myself with Flexbox too much. I've done the example below today in the hope I've got the basic layout principles correct.
Is the example below a valid Flexbox layout?
Many thanks,
Gary.
<!DOCTYPE html>
<html>
<head>
<title>Flexbox Layout</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="header">
<h1 class="name">The Best Site</h1>
<ul>
<li><a href="">Google</a></li>
<li><a href="">Facebook</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Amazon</a></li>
<li><a href="">Google</a></li>
<li><a href="">Facebook</a></li>
<li><a href="">Twitter</a></li>
<li><a href="">Amazon</a></li>
</ul>
</div>
<div class="container_mainbody">
<div class="section1">
<h1>Section 1</h1>
<p>Some type of content goes here.</p>
</div>
<div class="section2">
<h1>Section 2</h1>
<p>Some type of content goes here.</p>
</div>
<div class="section3">
<h1>Section 3</h1>
<p>Some type of content goes here.</p>
</div>
</div>
<div class="footer">
<p>The footer goes at the bottom of the page.</p>
</div>
</body>
</html>
*{
margin: 0;
padding: 0;
font-family: Arial;
list-style: none;
text-decoration: none;
box-sizing: border-box;
}
.header {
border: solid 1px red;
width: 100%;
display: flex;
flex-flow: row wrap;
align-items: flex-start;
}
ul {
display: flex;
flex-flow: row wrap;
align-self: center;
border: 1px dashed green;
justify-content: center;
flex: 1 1 auto;
}
li {
border: 1px solid white;
}
ul li a{
max-width: 100%;
padding:0 20px;
}
.container_mainbody {
display: flex;
flex-flow: row wrap;
flex: 1 1 100%;
border: 1px solid black;
}
.section1,
.section2,
.section3 {
display: flex;
flex-flow: row wrap;
flex: 1 1 33.33%;
border: 1px solid black;
}
.section1 h1,
.section2 h1,
.section3 h1 {
flex: 0 0 100%;
}
.footer {
display: flex;
display: row wrap;
border: 2px solid red;
}
2 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsLooks pretty good!
Two comments:
- container_mainbody doesn't need a flex property because it's a flex container but not a flex item.
- the flex property for ul and the "sections" can be simply
flex: 1
, sinceflex: 1 1 auto
is assumed, and for 3 sections all with flex-grow of 1, each will get 1/3 of the available space anyway.
![gary peart](https://secure.gravatar.com/avatar/efb497ca8d225dc1ef890edccdd2efde?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
gary peart
6,496 PointsBrilliant!!! Thanks for the feedback Steven, greatly appreciated.
It took me a couple of days in order to understand the idea of Flexbox. It was only when I thought of a HTML <table> layout structure that the Flexbox idea really clicked.