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 CSS Layout Techniques Flexbox Layout Build a Navigation with Flexbox

Daniel Popov
Daniel Popov
4,024 Points

Adding a image into the navigation

I have been attempting to add in a company logo as the first list item using this template; however, whenever I do this the entire navigation gets pushed and distorted. When I try to resize the image with CSS i also seem to be getting very distorted results. Is there a particular way I to include the logo image and resize in the nav bar?

<header class="main-header">
            <!-- <div id="logo"> <img src="img/chapter.png"> </div> -->
            <ul class="main-nav">
            <!--    <li class="main-logo"><h1><a href="index.html"> Logo</a></h1></li> -->
                <li class="main-logo"><img src="img/example.png"></li>
                <li><a href="index.html" data-icon="&#xe602;">Home</a></li>
                <li><a href="#" data-icon="&#xe601;">About</a></li>
                <li><a href="#" data-icon="&#xe603;">Subscribe</a></li>
                <li><a href="#" data-icon="&#xe600;">Contact</a></li>

            </ul>
</header>

.main-header,
.col {
    padding: 20px;
    width:100%;
}
.main-logo a, 
.main-nav a {
    display: block;
    color: white;
    text-decoration: none;
    text-align: center;
    padding: 8px 15px;
    border-radius: 5px;
    position: relative;
    overflow: hidden;
}
.main-logo img {width:20%;}
.main-nav a::before {
    font-family: 'icomoon';
    content: attr(data-icon);
    color: #fff;
    position: absolute;
    top: 10px;
    left: -30%;
    transition: .4s;
}
.main-nav a:hover::before {
    left: 10%;

}
.main-header {
        position: fixed;
        top: 0;
        width: 100%;
        height: 100px;
    }
    .main-nav {
        display: -webkit-flex;
        display: flex;
        height: 100%;
    }
    .main-nav li {
        margin-left: 8px;
        margin-right: 8px;
        -webkit-align-self: center;
        align-self: center;
        -webkit-flex-grow: 1;
        flex-grow: 1;
        transition: .5s;
    }
    .main-nav li:hover:not(.main-logo) {
        -webkit-flex-grow: 1.1;
        flex-grow: 1.1;
    }
Aisha Blake
Aisha Blake
Treehouse Guest Teacher

It would be helpful if you'd post the code you're using here. That way, it's easier for other people to see what exactly is going on.

1 Answer

I think the best way would be to create a "div" just for the logo, right before your navigation list. Then float the div containing the logo to the left and the rest of the navigation to the right. Like this:

      <div id="logo">
           <img src="logo.png" alt="">
      </div>
      <div id="navigation">
          <ul>
              <li>About</li>
              <li>Subscribe</li>
              <li>Contact</li>
          </ul>
      </div>           
 </header>