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

CSS

brandonlind2
brandonlind2
7,823 Points

My nav li are stretching outside their parents even though their width is set to max width 100%, does anyone know why?

I have a drop down menu and I noticed when it appeared a scroll bar appeared. I set it to display block so its constantly visible and changed its background color to red and I changed its parent's background color to blue, the drop down menu is taking up the width of its parent like it should but it looks like its parent the nav li with the class of main-nav are stretching out side its parent and taking the dropdown menus with the classes of sub nav with it. Does anyone know why main nav is stretching out side its parent?

https://jsfiddle.net/93qft4d7/1/

3 Answers

Hi,

That would be tricky and could have affect on responsive of your website. I recommending change this value to relative and don't worry about how drop down gonna works. When you going to add display none for those elements that should not change nothing there or if do you can also style nav list item separately right? There is tone of ways. For example if somehow after hide drop down something gonna crash you can use visibility property to handle this (display: none has affect for your content and position of this content when visibility still keep content on right place). But generally I wouldn't worry of drop down now and if you do that properly everything going to works fine.

Hi

The reason why you have stretched navigation items is because you did absolute position for parent element like .sub-nav. This mean you took this block out of scope and parent wrapper does not keeping width for this block no more.

Remove position: absolute from .sub-nav and it's gonna be ok.

PS. You can change this position to relative and it's also help.

brandonlind2
brandonlind2
7,823 Points

Thanks appreciate it :), is there a way to fix it without changing the position value. I feel like that might keep the drop down menu from working properly once its change back to display none.