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

Is there a way to get a nav container inside of a header container to fill 100% width of viewport?

Recently, I refactored some code to have mobile-first CSS -- a JavaScript-free drop-down navigation menu, in particular. Unfortunately, in the process I had to modify some HTML. I'm very happy with the mobile results but my desktop results now leave something to be desired, which is frustrating because I did have a somewhat nice desktop build (see example at http://samallen502.github.io, which represents my master branch, which I am hoping to commit my mobilefirst branch to after I resolve the mobilefirst branch's desktop nav/header issue).

For desktop, what I want is a responsive menu, with ul li #1 to be on the far left of the header and the other ul li to be on the far right of the header (similar to what you see at http://samallen502.github.io). For this, I am using flexbox. However, the ul are children of a nav, which has a header parent. Therefore, flexbox is working but not expanding to 100% width of the viewport, like I want .

Current index.html: https://github.com/samallen502/samallen502.github.io/blob/mobilefirst/index.html

Current main.css: https://github.com/samallen502/samallen502.github.io/blob/mobilefirst/css/main.css

Thanks for any help that anyone can provide. I understand that giving credit (discussion points) is important and will definitely do so.

1 Answer

Steven Parker
Steven Parker
221,292 Points

The nav has the class "wrapper", which sets the max-width to 768 pixels. If you remove that setting, it will expand across the header.

Also, there appears to e only one ul inside the nav, not two. So the entireul becomes the right-most item of the flexbox.

The devil is always in the details! Thank you, Steven Parker! I am going to commit my changes tonight, then clean up the CSS code a bit more tomorrow.

As a side note, if you take another gander at my GitHub branch, you'll see I ended up commenting out nav ul li #1 because it was much easier to use .title (nav h1) for the leftmost side of my navigational menu (on the desktop layout); I'll have to get the font sizes to appear about the same (.title versus .menuOptions) but that should be simple enough.

Thanks again! This has been a huge help. My stress nosedived when I got your answer earlier today at work. It was a total "eureka" moment. :-)