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 trialMatt Bryant
10,164 PointsTwo-column Image Gallery Float: Left Question
In the example of Nick's Style a Portfolio video where he makes a two-column photo gallery using the following CSS:
gallery li { float: left; width: 45%; margin: 2.5%; background-color: #f5f5f5; color: #bdc3c7; }
How does the float: left; not cause ALL individual image to start on a new line, floated to the left? In other words, what keeps the images on the right side column from floating to the left side of the parent container?
3 Answers
Steven Parker
231,198 PointsWhen an element is floated, it is taken out of the normal flow of the document and shifted to the left (or right) until it touches the edge of its containing element, or another floated element.
So as long as they don't exceed the width of the containing element, floated elements will all be placed on the same line.
For more details, see the MDN page on floats.
KAMRAN IMRANLI
4,107 PointsSteven Parker So you mean all the elements with the property "float: left;" in our html will be on the same horizontal line?
Steven Parker
231,198 PointsOnly if they fit, and there's nothing between them that would disturb the layout (such as something with a "clear: left" property).
KAMRAN IMRANLI
4,107 PointsSteven Parker <p>Thanks a <em> lot </em> :) </p>
Steven Parker
231,198 PointsKAMRAN IMRANLI — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!