繁体   English   中英

将Nav与徽标对齐

[英]Aligning Nav with Logo

我有一个标头在左侧的徽标,然后在底部的一个导航栏。 我希望将导航栏与徽标水平居中,但bottombottom padding-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");
    }
});

另外, 这里是一个演示。 让我知道您是否需要更多信息。

您可能想将它们浮动或内联到同一父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类下定义样式。

加:

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

JSFiddle演示

尝试这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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