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

HTML

Is it possible to include a paragraph as a list item?

I want an image and a paragraph to appear as a two-column list item. I used the "float" technique in my #gallery, but the paragraph is appearing below the image rather than next to it.

1 Answer

Yes absolutely! By default, the paragraph element is block-level so you simply have to change it to an inline element in the styling. Here I use inline CSS but you should use an external stylesheet if you've got that set up.

<ul style='text-decoration: none'>
    <li>
        <img src='http://placehold.it/150x150'>
        <p style='display: inline'>
            Hello, this is a paragraph next to an image in this list item.
        </p>
    </li>
    <li>
        <img src='http://placehold.it/150x150'>
        <p style='display: inline'>
            Hey, this is another paragraph next to an image in the second list item.
        </p>
    </li>
    <li>
        <img src='http://placehold.it/150x150'>
        <p style='display: inline'>
            Hello, one last paragraph next to my image in this unordered list!
        </p>
    </li>
</ul>

You can even wrap the p within a div and make the div the same height as the image. Then make the div an inline element using display. If you change the p element so that display: table-cell then you can do a vertical-align: middle to align the paragraph to the middle of the image (or top or bottom). Good luck!

Technically, this solution doesn't create two columns but it simulates it. To create two explicit columns you might want to check out grid frameworks like Bootsrap, Foundation, Skeleton, etc. or check out CSS Flexbox Treehouse videos.