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

The best way to lay out boxes on a page

I am looking into making a page similar to this one http://www.igshoutouts.com/niche/Fitness. The main part is the boxes as I want very similar features to those shown on the website. Using html and css what would be the best way to do this and could you give me a little guidance on how to go about it? So far I have lined up the boxers but not sure on how to get all the info inside each box, I have attached my code on what I have done so far. http://codepen.io/Johned22/pen/XjwQqZ Thanks in advance

I would use the bootstrap framework along with cards. https://v4-alpha.getbootstrap.com/components/card/

3 Answers

You could really reduce the repetitiveness of your code by using classes or targeting the actual divs instead of relying on ids.

 <div id="one" class="box">first</div>
<div id="two" class="box">second</div>
<div id="three" class="box">second</div>
<div id="four" class="box">second</div>
<div id="five" class="box">second</div>
<div id="six" class="box">second</div>
<div id="seven" class="box">second</div>
.box {
    float:left;
    width:200px;
    height: 400px;
    border:3px solid;
    margin-left: 12px;
    margin-right: 12px;
    margin-top: 24px;
}

#one{
    border-color: green;
}

#two,#five, #six {
    border-color: red;
}

#three,#four,#seven{
     border-color: blue;
}

If you inspect the divs for the fitness site, you'll see they are using bootstrap, So What I would do is to look at their structure and code. Use Bootstrap if you want and apply the "class="col-md-3 col-sm-6 col-xs-12 shoutout-normal" just as they have it on their page. If not I'd go inline block and use percents on the width to make them line up like in the site.

Theres nothing wrong with looking at their approach to solving an issue. Inspect on the site and take a look.

Thanks for all your advice