导航与徽标对齐

时间:2015-05-15 22:20:38

标签: javascript html css

我的标题左侧是徽标,底部是导航。我希望导航按照徽标水平居中,但bottompadding-bottom无效。我将图像更改为文本然后我可以做所有事情,但是使用图像它只是不起作用。

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");
    }
});

此外, HERE 是一个演示版。如果您需要更多信息,请与我们联系。

3 个答案:

答案 0 :(得分:1)

您可能希望将它们浮动或在同一父div中内联它们。 https://jsfiddle.net/awztqyso/1/

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

请注意,您有很多ID,但只能在css类下定义样式。

答案 1 :(得分:1)

添加:

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

<强> JSFiddle Demo

答案 2 :(得分:0)

试试这个

<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>

并应用这样的东西

#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*/