Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout Techniques Display Modes Column Layout with Inline-Block

Michal Broniewicz
Michal Broniewicz
6,669 Points

Column Layout do not fit.

Im trying to follow up with the video where Guil is showing column layout with inline-blocks. I know about margins I checked my font size and still i cant make them be displayed side by side. I have to change margin to like -50px to make it happen but its not looking like i would like it to be.. here is my css

/* Page Styles
================================ */

body {
    font: normal, sans-serif;
    color: #222;
    background-color: #edeff0;
  max-width: 90%;
  margin: auto;
}

.main-wraper li,
.main-logo,
.main-nav {
  display: inline;
  padding: 10px 20px;
  border-radius: 5%;
}

.main-nav li {
  margin-right: 10px;
}
.main-header {
  padding: 20px;
  white-space: nowrap;
}

.main-logo {
  margin-right: 50px;
}

/* Column Layout
================================ */

.col {
  display: inline-block;
  padding: 20px;
  margin-right: -5px;
}

.primary-content {
  width: 60%;
}

.secondary-content {
  width: 40%;
}

div {
  max-width: 100%;
}

Do you know what should i do to make it?

1 Answer

Ryan Field
PLUS
Ryan Field
Courses Plus Student 21,240 Points

So, what's happening here is that under normal circumstances (i.e. browser defaults), divs and other elements are given default padding, which is calculated on top of the dimensions you specify. So, while you may be telling one div to be 60% and the other to be 40%, there is still padding that is being automatically added on top of your percentages, which causes them too large to sit on one line together.

To fix this (and I always do this in my projects to avoid head-scratching scenarios like this), you can specify elements to be measured to include both borders and padding in the calculation. To do this, you can either specify it for each individual element (if you don't want it to happen with all elements), or you can simply use a universal selector to declare it, like this:

* {
  box-sizing: border-box;
}

Adding that to the top of your stylesheet should fix your problem! :)

Michal Broniewicz
Michal Broniewicz
6,669 Points

I totally forgot about it! Thanks!!

i got same problem, but adding

  • { box-sizing: border-box; } don't fix it for me where is the problem?

/* Page Styles ================================ */ *{ list-style:none; box-sizing: border-box; }

body { font: normal 1.1em/1.5 sans-serif; color: #222; background-color: #edeff0; } .main-wrapper{ width:90%; margin:auto;

}

/* Layout Element Colors ================================ */

.main-header { background-color: #384047; } .main-logo { background-color: #5fcf80; } .main-nav li { background-color: #3f8abf; } .primary-content { background-color: #caebf6; } .secondary-content { background-color: #bfe3d0; } .main-footer { background-color: #b7c0c7; }

/* Header, Banner and Footer Layout ================================ */

.main-header{ padding:20px; display:table; width:100%; min-width:150px; } .main-logo, .main-nav, .main-nav li{ display:inline-block; } .main-logo, .main-nav li{

border-radius:5px;

} .main-logo{

width:120px;

} .main-nav li{

margin-left: 10px;

} .main-nav{ padding-left:50px; } .main-logo a, .main-nav a { color: white; text-decoration: none; display:block; text-align:center; padding:10px 20px; } .main-nav{ margin:0; padding:0;
} .main-logo, .main-nav{ display:table-cell; vertical-align:middle; } /Column Layout/ .col{ display:inline-block; padding:20px; margin-right:-5px; } .primary-content{ width:60%; } .secondary-content{ width:40%; }

/Media Queries/ @media (max-width:768px){ .main-logo, .main-nav, .main-nav li{ display:block; width:initial; margin:initial;

}
.main-nav{
    padding:initial;
}
.main-nav li{
    margin-top:15px;
}

}