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

CSS

Create three columns layout using inline-block.

I am trying to make a page with three column layout using inline-block display property, and a width of 33.333% for each column to fit the whole width. the problem I could not have the required layout using width=33.3333% it shows only two columns in the row. and when I change the width to 33% I get three columns layout but ofcourse not fitting the whole width. here's my code: <p data-height="268" data-theme-id="9486" data-slug-hash="wJGvq" data-default-tab="result" data-user="eiyadz" class='codepen'>See the Pen <a href='http://codepen.io/eiyadz/pen/wJGvq/'>wJGvq</a> by Eiyad Ziyadah (<a href='http://codepen.io/eiyadz'>@eiyadz</a>) on <a href='http://codepen.io'>CodePen</a>.</p> <script async src="//codepen.io/assets/embed/ei.js"></script>

2 Answers

The reason you can't set it to a width of 33,3333% is because you have the spaces between each content block. If you were to add up the three blocks you'd get a width of 99,999% then add that spacing and that would exceed the width of 100%.

The space that you are seeing is not a margin problem, it is simply a normal space like the ones used between words.

So what you need to do is to remove the spacing. You can do this by adding float: left to your css. Like this:

.content {
    margin: 0.25em auto;
    vertical-align: top;
    border: 1px solid;
    display: inline-block;
    width: 33.3333%;
    float: left;
}

If you for some reason don't wish to float your sections you can also do this:

<div class="content">
    <h3>content 1</h3>
</div
    ><div class="content">
    <h3>content 2</h3>
</div>

OR

<div class="content">
    <h3>content 1</h3>
</div><!--
    --><div class="content">
    <h3>content 2</h3>
</div>

This is called minimized HTML and is completely valid code.... albeit it does feel weird, doesn't it?

Hope this helps.

Try the float: left; in your css. This should fix the problem.

.content {
     margin: 0.25em auto;
     vertical-align: top;
     border: 1px solid;
     display: inline-block;
     width: 33.3333%;
     float: left;
}