html - 导航菜单中间的中心标志

标签 html css

我希望在居中的顶部导航菜单中间显示我的 Logo 。就目前而言,我的 Logo 位于其顶部。如果我将菜单项拆分到不同的容器中,然后使用边距和填充来完成此操作,会不会最简单?还是有更有效的方法?

这是一个 JS Fiddle,显示了我当前的场景。 JS Fiddle

这是我当前的 CSS:

.container {
width:960px;
margin:0 auto;
}
header, main{
    display: block;
}
.container-narrow {
margin:0 auto;
width:640px;
}

h1.logo {
width:300px;
margin:0 auto;
text-indent:100%;
overflow:hidden;
white-space:nowrap;
}

body h1 {
background:url(http://placehold.it/300x80) no-repeat;
height:80px;
}

body section.menu,body header.top-section {
background:url(../img/menu-bg.png) repeat;
padding:60px 0;
}

body header.top-section {
padding:40px 0;
position:absolute;
top:0;
left:0;
width:100%;
z-index:50;
}

#menu_container {
    letter-spacing: 2px;
    font-family:'intro_regular', sans-serif;
    font-size: 1.3em;
    line-height: 1.3em;
    position: fixed;
    margin: 0;
    /*margin-top: -70px;
    position: relative;*/
    z-index: 20;
    left: 0;
    right: 0;
    text-align: center;
    padding: 6px;
    height: 40px;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    -ms-box-sizing: border-box;
    -o-box-sizing: border-box;
    box-sizing: border-box;
}
#menu_container .nav ul { list-style: none; overflow: auto; }
#menu_container .nav li { float: left; padding: 0.4em 0.8em; font-size: 0.9em; line-height: 1em; cursor: pointer; }
#menu_container .nav li a { text-decoration: none; text-transform: uppercase; }
#menu_container .nav li:hover a,
#menu_container .nav li.active a { color: #fff !important; }
#menu_container .nav li.contact_screen:hover a,
#menu_container .nav li.contact_screen.active a { color: white !important; }
#menu_container .nav li a { color: #000000; }
#menu_container .nav li a { transition: all 400ms; -webkit-transition: all 400ms; }
#menu_links { display: inline-block; }
#menu_button { display: none; color: white; cursor: pointer; text-align: right; padding: 0 0.8em; }
#menu_button i { font-size: 1.3em; margin-right: -0.3em; color:#bc9321;}
#menu_links li:first-child {}

最佳答案

我最近遇到了这种情况。我通过绝对定位 Logo 来实现它,然后使用 :nth-child 选择器来定位 Logo 两侧的元素并添加边距以腾出空间。

Here's the Fiddle

:nth-child 很棒,但您可能需要一组后备样式 older browsers .

关于html - 导航菜单中间的中心标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22056858/

相关文章:

javascript - 从浏览器(不是移动设备)打开 native 应用程序

html - 我应该为一个元素使用什么选择器,这取决于伪元素的悬停行为?

javascript - 是否有一个库允许我在页面底部加载 jQuery 但仍然用 $(function() {}) 填充我的 html

html - Flexbox:在底部和中心之间对齐?

html - 输入框框,去掉 "background"颜色

html - 大多数电子商务网站中的“我的帐户”链接。登录前为什么要有一个?

javascript - 将 URL 更改为其他内容?

javascript - 如何淡入淡出每一个词都有一点延迟来制作一个很棒的标题

html - 请问伪类 :checked will select inputs with type radio or checkbox, 而不是 <option> 元素?

css - 即使没有空格也可以剪切长文本