Html 在导航菜单的中间居中显示徽标 我想在居中的顶部导航菜单中间显示我的徽标。就目前的情况而言,我把徽标放在它上面。如果我将菜单项拆分为不同的容器,然后使用边距和填充来实现这一点,这是否最简单?还是有更有效的方法

Html 在导航菜单的中间居中显示徽标 我想在居中的顶部导航菜单中间显示我的徽标。就目前的情况而言,我把徽标放在它上面。如果我将菜单项拆分为不同的容器,然后使用边距和填充来实现这一点,这是否最简单?还是有更有效的方法,html,css,Html,Css,下面是一个JS提琴,显示了我当前的场景 以下是我当前的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:now

下面是一个JS提琴,显示了我当前的场景

以下是我当前的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类放在中间的一个里。

        <div id="menu_links" class="nav">
            <ul>
                <li class="home_link"><a href="#splash_wrapper">Home</a></li>
                <li class="menus_link"><a href="#menus_wrapper">Menus</a></li>  
<li class="logo">Restauraunt</li
                <li class="contact_link"><a href="#contact_wrapper">Contact</a></li>
                <li class="reservations_link"><a href="#reservations_wrapper">Reservations</a></li>
            </ul>
        </div>


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


    :n个child
    很好,但您可能需要一组备用样式。

    您考虑过CSS3 display:flex吗


    如果我是你,我会使用第n个子选择器对中间的两个
    li
    元素(可能是左
    li
    右侧的160px和右
    li
    左侧的160px,假设它们是偶数)应用偶数填充,“天哪,一定有人以前写过这方面的东西。”不幸的是,这在IE8中不起作用。我没有把它作为先决条件。幸运的是,如果IE8继续它的发展趋势。我想如果IE8是必须的话,JavaScript解决方案或一点黑客技术会起作用。使用div作为nav而不是使用nav标记也是如此。没有异议。