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

Horizontal nav bar: image (logo) on the left, menu on the right. But I can't make it work!

I'm trying to code a responsive horizontal navigation bar across the top of my website.

On a small screen, I was trying to center the logo and put the menu bar to the far right. On screens over 515px, I'm trying to put the logo (an img) on the far left of the container, and a menu button (another img) on the far right, leaving the space between white.

When I try to add a media query for a bigger screen, I get no response. I'm using flexbox and the space-between feature, but it won't work!

Main container is called 'mainNav'. My logo is called 'logo' My menu button is called 'menu'.

<div class="mainNav">
            <img class="logo" src="Logo.png" id="logo" a href="index.html"> 

            <img class="menu" src="img/menu.png" id="menuButton" a href="menu">
</div>

Here's my small-screen css:

.mainNav {
    display: flex;
    align-items: center;
    flex-direction: row;
    margin: auto;
    width: 80%;
    padding: 2% 0;
}

.logo {
    margin: auto;
    width: 50%;
    height: 100%;
}

.menu {
    padding-right: 2%;
}

and here's my bigger screen css (that won't work):

@media (min-width: 515px) {

    .mainNav {
        display: flex;
        flex direction: row;
        justify-content: space-between;
        }

}

Thanks for any help!!!

What browser and version do you use?

I'm using Chrome Version 49.0.26 (I think that's the newest one?).

I'm coding on Brackets and viewing it in the Live Preview.

1 Answer

Got it!

Under the media query, I needed to remove the old formatting of my .logo and .menu.

I replaced it with:

.logo,
.menu {
    margin: 0;
}

and that did the trick!