Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout Basics Page Layout with the Float Property Creating a Horizontal Navigation with Floats

horizontal navigation with floats

"With floats, we don't have to worry about the the extra whitespace that can appear when using inline or inline-block display." "Floated elements will sit adjacent to each other regardless of the HTML whitespace between them."

we never changed the display value of any of the elements we worked with. why are they acting like inline block elements? Im very confused.

1 Answer

Michael Shields
Michael Shields
12,638 Points

The <a> elements that are descendants of the <h1 class="name"> and the <ul class="main-nav"> elements are declared as block-level display in our style.css file.

When we declare a float value we are manipulating the normal document flow. That floated element now accepts all block-level element values like width, height, padding, and margin, BUT the floated element doesn't exist on it's own line (i.e. doesn't create HTML whitespace before and after the element like a block-level <div> would) and the surrounding content flows around it, behaving like an inline element would.