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 trialKafe Hezam
11,070 PointsWhy when there's no padding on the items the items fit in the container??
1- Why when I don't give padding to the items the items fit in the container?
2- When I give the items width the items fit perfectly in the container?
I really appreciate if you can answer these question :)
- {
box-sizing: border-box;
}
body {
font-size: 1.35em;
font-family: 'Varela Round', sans-serif;
color: #fff;
background: #e8e9e9;
padding-left: 5%;
padding-right: 5%;
}
.container {
padding: 10px;
background: #fff;
border-radius: 5px;
margin: 45px auto;
box-shadow: 0 1.5px 0 0 rgba(0,0,0,0.1);
display: flex;
}
.item {
color: #fff;
/* padding: 15px;/ / no padding */
margin: 5px;
background: #3db5da;
border-radius: 3px;
width: 200px;
}
2 Answers
Dmitry Polyakov
4,989 Points1- Why when I don't give padding to the items the items fit in the container?
It depends on what padding you will give the items. Let's say if you give them 130px padding, they won't fit into the container because total width of the items exceeds the width of the container. They will stretch in 1 row outside of the container. To fix that you also need to set up a flex-wrap property on a container itself. By default it's nowrap. It means that elements inside the container stay in one row and don't wrap to the next row. If you set up flex-wrap: wrap; on a container, then no matter how big padding you'll give to the items they will stay inside the container go down to the second row within the container.
/* ================================= Flexbox ==================================== */
{ box-sizing: border-box;
}
body {
font-size: 1.35em;
font-family: 'Varela Round', sans-serif;
color: #fff;
background: #e8e9e9;
padding-left: 5%;
padding-right: 5%;
}
.container {
padding: 10px;
background: #fff;
border-radius: 5px;
margin: 45px auto;
box-shadow: 0 1.5px 0 0 rgba(0,0,0,0.1);
display: flex;
justify-content: space-around; flex-wrap: wrap;
}
.item {
color: #fff;
padding: 135px;
margin: 5px;
background: #3db5da;
border-radius: 3px;
/width: 200px;/
}
2- When I give the items width the items fit perfectly in the container? Almost the same as the first point. Depends on what width you give the items and how flex-wrap property is set up on a container.
Kafe Hezam
11,070 PointsSteven Parker,
I reposted the question because I never gotten an answer.
Thank you so much for the help, Dmitry!
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThis appears to be a duplicate of your previous question (but without the benefit of code formatting in the original).