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 How to Make a Website Styling Web Pages and Navigation Build Navigation with Unordered Lists

Terrance Corley
Terrance Corley
11,990 Points

Can someone explain to me why we are floating the header to the left in this instance with a width of 100%?

I understand floats, but I'm not understanding why we are floating our header to the left and then specifying a width of 100%. Nick says doing so now has no practical purpose for the development of the mobile version of the site, but it will make sense when we start coding the desktop version of the site. I've completed the project and still don't understand why we had to float the header to the left. If I comment out the float declaration from the header though, most of my header disappears.

Any thoughts?

Luis Magaña
Luis Magaña
13,042 Points

My best guess would be that he was taking a mobile first approach, so in specifying a float left at the lowest view port width setting would allow him to scale up for larger devices and specify a different a different width maybe 50% and divide header into two sections. Thats my best guess would need to see the markup to make a better assessment.

Terrance Corley
Terrance Corley
11,990 Points

Hi Luis Magaña,

Jason was actually able to explain to me the issue. What you said is something I will definitely keep in mind when working on future projects. Thanks for the feedback!

2 Answers

Hi Terrance,

For the desktop layout, the logo and the navigation are being floated. Normally, a parent element will not contain its floated children and will collapse in height. This is what you experienced when you removed the float declaration from the parent header element.

Floating the parent is one of several ways to force an element to contain its floated children. So Nick floated the header early on knowing he was going to float the children later.

You may have heard of the clearfix hack. This is another way to solve the problem.

Terrance Corley
Terrance Corley
11,990 Points

Hey Jason!

You explained this perfectly. I now understand exactly what's going. Thanks for the help!

Kevin Heck
PLUS
Kevin Heck
Courses Plus Student 1,290 Points

Hi, Terrance. The reason that you are floating the images is because when your site is viewed on a device larger than a mobile phone or smaller tablet, the images will expand to take up the space available. It is a type of responsive code that allows for flexibility between view screens.

Also, the reason that Nick is building the mobile version first is because it is easier to build a site for mobile view screens and then layer a little code for desktop than it is to build for desktop and layer a lot of code for mobile view screens.

Hope this helps!!!

Kevin Heck
Kevin Heck
Courses Plus Student 1,290 Points

p.s. if you take the tab that your site comes up on in your browser out of fullscreen and scale it down from right to left, you will see the images move from three columns down to two to allow for an un-clustered view of the images on a smaller view screen.

Terrance Corley
Terrance Corley
11,990 Points

Hi Kevin,

Thanks for taking the time to respond to my issue but I was actually asking about the header element itself, not the image gallery. Thanks for taking the time though!