将我的徽标置于自定义标题上并右对齐导航

时间:2013-08-03 19:45:57

标签: html css centering

如果你在JSFiddle上查看它,你必须让结果窗口更大,看看我在说什么。徽标应该位于半圆和标题的顶部,导航应该在标题中居中并​​且右对齐。

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

HTML

    <div class="header">
        <div class="container">
            <a href="#"><img class="logo" src="img/onewaylogo.png"></a>
            <nav>
                <a href="#">Home</a>
                <a href="#">About</a>
                <a href="#">Let's Partner</a>
                <a href="#">Contact</a>
            </nav>
        </div>
    </div>

CSS

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

.header .container {
    position: relative;
    height: 100px;
    width: 85%;
    margin: 0 auto;
    text-align: center;
}

.header:after {
    content: '';
    position: relative;
    bottom: 0;
    display: block;
    margin: 0 auto;
    background: #f6f6f6;
    width: 150px;
    height: 75px;
    border-radius: 0 0 75px 75px;
}

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

.header nav {
    float: right;
    position: relative;
    width: 320px;
}


.logo {
    position: relative;
    top: 50px;
    display: inline-block;
    width: 150px;
    height: 100px;
    z-index: 100000;
    margin: 0 auto;
}

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

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

1 个答案:

答案 0 :(得分:1)

Fiddle Working

您可以通过将元素的宽度和位置设置为absolute来居中 在这种情况下:

.logo {
    position: absolute;
    margin: 0 50%;
    width: 150px;
    left: -75px; // total width half  (75px)
    ...
}