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

Blair Owens
Blair Owens
8,235 Points

Logo image in header positioning

I am trying to position the leaf graphic on my logo but I am having trouble getting the position correct. When I put the position to absolute, I am able to adjust the graphic using margin to get my desired position. But as with absolute, the graphic stays in the same position even when scrolling, when I want it to stay attached to the logo. I am not sure if I am using the right css to complete my request, any idea's on what I can do? Thanks!! PS my code may be a little dodgy, I am just learning! Any tips would also be appreciated.

I posted the image on tumblr since I can't upload pictures. This is my desired look, but again this was done with position: absolute, which keeps the image in the same position when scrolling as opposed to staying with my logo. http://blairnotwaldorf.tumblr.com/post/92044664673

HTML

<header>
    <div id="logobox">
    <a href="index.html" id="logo">
        <img src="Images/leaf1.png" id="leaflogo">
        <h1>NiagaraClean</h1>
        <h2>Cleaning Services from Nature</h2>
        </a>
        <h3 id="topphone"><a href="tel:1-800-564-3928">1-800-564-3928</a></h3>
    </div>  
        <p id="bookservice">Book Your Service</p>
        <div id="navigation">
            <nav>
                <ul>
                    <li><a href="about.html">About</a></li>
                    <li><a href="services.html">Services</a></li>
                    <li><a href="products.html">Products</a></li>
                    <li><a href="locations.html">Locations</a></li>
                </ul>
            </nav>
        </div>
</header>

CSS

header {
    width: 100%;
    text-align: center;
}

#logo {
    text-align: center;
    margin: 0 auto;
}

#logobox {
    height: 80px;
    margin: -10px 10px 0;
}

#leaflogo {
    height: 30px;
    width: 30px;
    position: absolute;
    margin: -13px -5px 0;
}

h1 {
    font-family: 'Antic Didone', serif;
    color: #50C738;
    font-size: 2.5em;
    font-weight: normal;
    position: relative;
    clear: both;
    line-height: 1em;
}

h2 {
    font-size: 0.75em;
    color: #1CABE8;
    margin: -23px 0 15px;
    font-weight: normal;
}

h3 {    
    font-size: 1.35em;
    color: #50C738;
    font-weight: normal;
    line-height: 1em;
}

#bookservice {
    background-color: #1CABE8;
    display: block;
    width: 100%;
    color: #FFF;
    margin: 29px 0 16px;
    padding: 10px;
}

#topphone {
    margin: -1px 0 0;
}

Thanks!!

1 Answer

Jacob Miller
Jacob Miller
12,466 Points

If you set #logobox to have a position of relative, you'll be able to move the leaf around with absolute positioning and still have it scroll with the page, because it will be positioned absolutely, but relative to it's parent, not to the page.

Blair Owens
Blair Owens
8,235 Points

Awesome! Thanks a lot :D