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

Alexandra Ruskovski
Alexandra Ruskovski
12,600 Points

two layout column

Hi, I am trying to make a two layout column. On the primary col I have a photo and a paragraph and on the second one I have a div(later it will become a gallery). The total width is 90%. The first col should take 30% and the second should take 60%. I have already tried to give a margin-right negative value, but is not working, The div is still under the primary col but on the right side, while the primary col is on the left side. Please, help!!

4 Answers

Alexandra Ruskovski
Alexandra Ruskovski
12,600 Points

.wrapper { width: 90%; margin: 0 auto; max-width: 1200px; } .primary{ display: inline-block; width: 30%; }

.second {
    display: inline-block;
    width: 60%;
}
Alexandra Ruskovski
Alexandra Ruskovski
12,600 Points

<div class="wrapper">

    <div class="primary col">
        <h2>
            <img src="img/eu.jpg" alt="" class="eu">
            ABOUT ME
        </h2>
        <p> blablabla</p>
    </div>

    <div class="second col"> Gallery </div>

</div>
Jamie Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

Hi, I have used your code in my editor and have the result you want, a two column layout side by side. However, I don't have the image you are trying to use. Do you have a fluid responsive image? By setting the img rule in your css:

img {
  max-width: 100%; /* Stops images from breaking out of their containers and makes them display fluidly with the browser window. */
}

Also, you don't need to apply the same CSS rule twice like you did with the display: inline-block rule. You can do that once by targetting the class col like you have created in your HTML. Since both columns share the class col, it makes sense to apply the CSS rule once. It is good practice to get out of the habit of duplicating CSS rules when you don't need to.

.wrapper {
  width: 90%;
  margin: 0 auto;
  max-width: 1200px;
}

.col {
  background: #edbda5; /* I displayed a background so that you can see the columns more clearly. */
  display: inline-block;
}

.primary {
  width: 30%;
}

.second {
  width: 60%;
}