html - header : Logo to the left, 向右导航。 (垂直居中对齐)

标签 html css css-float

我无法将导航对齐到页眉右侧。在网络上搜索,我认为问题是因为我将元素垂直对齐到中心,而 float 选项不适用。

有什么线索吗?

参见:http://jsfiddle.net/PabloArteeL/T7JDJ/

HTML:

<header>
    <div class="logowrapper" style="padding-left:1em;">
        <div class="logo"></div>
    </div>
    <nav><a href="#">SOME LINK</a>
    </nav>
</header>  

CSS:

header {
    background-color: #eaeaea;
    height: 80px;
    margin: 10px;
}
.logowrapper {
    display: table-cell;
    height: 80px;
    vertical-align: middle;
    text-align: center;
}
.logo {
    display: inline-block;
    background-image: url("http://placehold.it/250x40");
    width: 250px;
    height: 40px;
}
nav {
    right: 0px;
    display: table-cell;
    vertical-align: middle;
}
nav a {
    color: black;
    text-decoration: none;
}

期望的效果:

Desired Effect

最佳答案

你需要给<nav>宽度和变化text-align:left;text-align:center;否则它不会居中文本:

nav {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    width:400px;
}

结果: enter image description here

JSFiddle

关于html - header : Logo to the left, 向右导航。 (垂直居中对齐),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24977087/

相关文章:

javascript - 如何让一个div出现,然后一直向右滑动,然后慢慢淡出?

javascript - 如何从我的 HTML 嵌入视频重定向到另一个网页?

javascript - 在 react 中在两个外部 css 文件之间切换

html - 圈出彼此相邻的 DIV 元素

iphone - html img 标签中的图像在我的 iPhone 应用程序中变得模糊

javascript - “onclick”存储值不起作用

html - Twitter BootStrap 背景图片

html - 按钮插件中的 Bootstrap 字形图标

css - 2列CSS float 图像不同大小

css - 如何让我网站上的框堆叠成两列?