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

Make images horizontal

Can anybody help me with this code, the images are running vertical and I need them to be horizontally beside each other

http://pastebin.com/AfPQivhr

James Barnett
James Barnett
39,199 Points

It's easier to help someone debug an issue when it's in an interactive code playground like codepen rather then a static block of text.

9 Answers

Andrew Shook
Andrew Shook
31,709 Points
#crossfade{
        width:auto;
        display:inline-block;
        vertical-align:top;
    }
Andrew Shook
Andrew Shook
31,709 Points

Are you wanting to know how to line up the crossfade divs? Also, you need to change crossfade from and id to a class. Id's are only suppose to be used once per page. If an element has a selector that is used multiple times on a page then the selector needs to be a class.

Yes i want to know how to line them up horizontally

Heres the codepen http://codepen.io/anon/pen/lLjdb

James Barnett
James Barnett
39,199 Points

Dakota Conway - Use inline-block:

#crossfade { display: inline-block; }

Read more about inline block over on learnlayout.com

Also as Andrew Shook mentioned you really should change crossfade from an id to a class as it's currently not valid CSS.

it's still not working, it seperates the images

James Barnett
James Barnett
39,199 Points

Update your codepen with what you've got so far

Tom Bedford
Tom Bedford
15,645 Points

You have the images set at position: absolute; left: 0; which is why they are all ontop of one another.

#crossfade img {
    position:absolute;
    left:0;
}

This should be much better.

Tom Bedford
Tom Bedford
15,645 Points

Also your anchor tags look a bit broken.

You have

<a href="#"</a>

They should be

<a href="#">content to link</a>

If you are wanting :hover to change the appearance of the images it may not be best having two different images for each in the .html. You could use background images (changing on :hover - I would normally use sprites for these so there is no white flash when the second image loads in) or just apply an opacity affect when hovering (try a decimal so you can still see part of the original image).

thank you

One last question, when i tried to space the images apart with <hr> it just put it under the next image

http://codepen.io/anon/pen/bmpng

Tom Bedford
Tom Bedford
15,645 Points

Add a margin to .crossfade to space things out.

Do look at your anchor tags though as (for the way you have it set out) you should have the .html like this:

    <a href="#"><img class="bottom" src="http://i.imgur.com/lIB0lAZ.png" /></a>

NOT like this:

    <img class="bottom" src="http://i.imgur.com/lIB0lAZ.png" /><a href="#"</a>