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

Alignment issues with floating lists

I have two unordered lists that I want to float side by side. Each <li> in the list contains a header and an image. I have managed to get them to float alongside eachother however because the headline in each list is a different length if the viewport is adjusted one headline will drop down to two lines. When this happens one image will drop down too and make the images not aligned. Is there a way to solve this?

5 Answers

Ahh, that's the classic height alignment issue. I would check out an article like this for that issue.

http://css-tricks.com/fluid-width-equal-height-columns/

Or the quick fix is it give those a min-height greater than your tallest element.

Great, thank for your help Nick :)

Could you post your code? That would help in troubleshooting.

/*Float commands*/

.left_column,
.right_column {
    width: 50%;
}

.left_column {
    float: left;
}

.right_column {
    float: right;
}

/* Float Clearfix ------------------ */

.group:after {
  content: "";
  display: table;
  clear: both;
}
<div class="left_column">
                    <ul>
                        <li>
                            <h3>Short header</h3>
                            <img src="images/c100/File7.jpg" alt="C100">
                            <a href="#link"><p>More information</p></a>
                        </li>
                    </ul>
                </div>

<div class="right_column">
                    <ul>
                        <li>
                            <h3>Longggggger header</h3>
                            <img src="images/c100/File7.jpg" alt="C100">
                            <a href="#link"><p>More information</p></a>
                        </li>
                    </ul>
                </div>

If your issue is the actual image breaking the layout, you'll want to give some kind of width to the image itself too.

Something like this

.right_column img, .left_column img{
  width:100%;
}

Otherwise the image just hangs out in it's original width, potentially breaking the layout.

Hi Nick thanks for your reply.

https://www.dropbox.com/s/bsa7envh68lhaz7/image.jpg?dl=0

above is a link to an image of the issue im having. I understand why it is doing it I just dont understand how i fix it. If you see the first two boxes, the headline on the right uses an extra line than the left so everything goes out of alignment. How do i make it so that the image and borders look more tidy, if that make sense?