简体   繁体   中英

Aligning Nav with Logo

I have a header with a logo on the left, then a nav on the bottom. I'd like the nav to be horizontally centered with the logo, but bottom and padding-bottom isn't working. I changed the image to text and then I could do everything, but with the image it just doesn't work.

HTML

<header class="cf">
    <div id="nav">
        <a href="#"><img class="logo" src="HEADER/banner.png" width="300" height="100" alt="Next Gen"></img></a>

        <div id="nav-list">
            <ul id="list">
                <a href="#"><li>HOME</li></a>
                <a href="#"><li>GALLERY</li></a>
                <a href="#"><li>ABOUT US</li></a>
                <a href="#"><li>SPONSORS</li></a>
                <a href="#"><li>ROSTER</li></a>
            </ul>
        </div>
    </div>
</header>

<section class="section one">
    <h2>One</h2>
</section>
<section class="section two">
    <h2>Two</h2>
</section>
<section class="section three">
    <h2>Three</h2>
</section>
<section class="section four">
    <h2>Four</h2>
</section>

CSS

/* Body */

* {
    margin: 0;
    padding: 0;
}

body {
    font-size: 16px;
    line-height: 1.4em;
    color: #222;
    font-family: 'Raleway', sans-serif;
}

/* Header */

    /* Shrinking */

        /* ClearFix */

        .cf:before,
        .cf:after {
            content: " ";
            display: table; 
        }

        .cf:after {
            clear: both;
        }

        .cf {
            *zoom: 1;
        }

        /* Header Styles */

        header {
            width: 100%;
            height: 100px;
            background: #02236a;
            position: fixed;
            z-index: 2;
            box-shadow: 0 4px 4px rgba(0,0,0,0.1);
        }

        .small {
            height: 80px;
        }

        .small .logo {
            width: 240px;
            height: 80px;
        }

        .nav {
            width: 80%;
        }

        /* Transitions */

        header, .logo {
            -webkit-transition: all 1s;
                    transition: all 1s; 
        }

    /* Navigation */

        ul li {
            float: left;
            margin-left: 50px;
        }

/* Miscellaneous */

a {
    text-decoration: none;
}

li {
    list-style: none;
}

/* Delete */

.section {
    max-width: 100%; 
    height: 42em;
    padding: 10px;
}

.section h2 {
    color: #fff;
    font-size: 6em;
    font-weight: 200;
    text-align: center;
    padding: 2.5em 0;
}

.one {
    background: #6bb6ff;
}

.two {
    background: #1E90FF;
}

.three {
    background: #8B4789;
}

.four {
    background: #872657;
}

JavaScript

$(document).on("scroll", function () {
    if ($(document).scrollTop() > 25) {
        $(".cf").addClass("small");
    } else {
        $(".cf").removeClass("small");
    }
});

Also, HERE is a demo. Let me know if you need any more information.

You may want to float them or inline them in the same parent div. https://jsfiddle.net/awztqyso/1/

.logo {
    float: left;
    width: 300px;
    height: 100px;
}
.nav-list {
    float: left;
    padding-top: 45px;
    height: 100px;
    width: 650px;
}

Notice that you have a lot of IDs but you only define styles under css classes.

Add:

.logo {
    float:left;
    width: 200px;
}

JSFiddle Demo

try this

<div id="nav">
    <div id="logo-box">
        <a href="#"><img class="logo" src="HEADER/banner.png" width="300" height="100" alt="Next Gen"></img></a>
    </div>
    <div id="nav-list">
        <ul id="list">
            <a href="#"><li>HOME</li></a>
            <a href="#"><li>GALLERY</li></a>
            <a href="#"><li>ABOUT US</li></a>
            <a href="#"><li>SPONSORS</li></a>
            <a href="#"><li>ROSTER</li></a>
        </ul>
    </div>
</div>

and apply someting like this

#nav{height: 100px; width: 100%; }
#logo-box{width: 300px; margin-left: 20px; float:left;}
#nav-list{margin-left: 360px; width:600px;} /*margin-left should be more than the 
 image-box width + image-box margin-left at least*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM