如何使徽标居中并导航右对齐,然后堆叠在顶部以便响应

时间:2013-08-03 03:10:06

标签: html css media

通过将徽标置于中心然后导航器右对齐并在标头内垂直居中,然后当它缩小到响应模式时它将叠加在另一个上面,我遇到了问题。我可以通过导航位置获得所需的桌面模式效果:绝对;但随后它搞砸了我的响应式查询。

有人有想法吗?

这是小提琴:http://jsfiddle.net/W37Wq/1/

HTML

<div class="header">
        <div class="header-inner">
            <a href="www.google.com"><img class="logo" src="http://www.techcityng.com/wp-content/uploads/2013/07/google.jpg"></a>
            <nav>
                <a href="#">Home</a>
                <a href="#">About</a>
                <a href="#">Let's Partner</a>
                <a href="#">Contact</a>
            </nav>
        </div>
    </div>

    <header class="clearfix">

CSS

.header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #f6f6f6;
    z-index: 10000;
    height: 100px;
    overflow: hidden;
}

.header .header-inner {
    width: 90%;
    max-width: 69em;
    margin: 0 auto;
    padding: 0 1.875em;
    text-align: center;
}

.header h1,
.header nav a {
    line-height: 100px;
}

.header h1 {
    text-transform: uppercase;
    color: #333;
    letter-spacing: 4px;
    font-size: 1em;
    display: block;
    block;
    margin: 0 auto;
    text-align: center;
    float: none;
    overflow: hidden;
}

.header nav {
    display: inline-block;
    text-align: right;
    list-style: none;
    margin-left: 5em;
    position: absolute;
}

.header nav a {
    color: #aaa;
    font-weight: 700;
    margin: 0 0 0 20px;
    font-size: .9em;
}

.header nav a:hover {
    color: #333;
}

.logo {
    display: inline-block;
    max-width: 198px;
    max-height: 100px;
}

@media screen and (max-width: 55em) {

    .header .header-inner {
        width: 100%;
    }

    .header .logo,
    .header nav {
        display: block;
        margin: 0 auto;
        text-align: center;
        float: none;
    }

    .header .logo,
    .header nav a {
        line-height: 50px;
    }

    .header nav a {
        margin: 0 10px;
    }

    .header .logo,
    .header.header-shrink nav a {
        line-height: 45px;
    }

    .header .logo {
        font-size: 2em;
        max-height: 60px;


    }

    .header.header-shrink nav a {
        font-size: 1em;
    }
}

@media screen and (max-width: 32.25em) {
    .header nav a {
        font-size: .9em;
    }
}

@media screen and (max-width: 24em) {
    .header nav a,
    .header.header-shrink nav a {
        line-height: 1;
    }
}

http://jsfiddle.net/W37Wq/1/

谢谢!

2 个答案:

答案 0 :(得分:1)

http://jsfiddle.net/W37Wq/4/

改变这堂课:

    .header {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        background: #f6f6f6;
        z-index: 10000;
        height: 110px;
        overflow: hidden;
    }

    .header .header-inner {
        width: 90%;
        margin: 0 auto;
        padding: 0% 5%;
        text-align: center;
    }

    @media screen and (max-width: 55em) {

        .header .header-inner {

        }

        .header .logo,
        .header nav {
            display: block;
            margin: 0 auto;
            text-align: center;
            float: none;
            width:90%;
        }
    }

答案 1 :(得分:0)

只需在媒体查询通话中添加position:relative;

@media screen and (max-width: 55em) {

    .header .logo,
    .header nav {
       display: block;
       margin: 0 auto;
       text-align: center;
       float: none;
       position:relative;
    }
}

http://jsfiddle.net/gGGLd