gpt4 book ai didi

css - 无法让导航栏在页面上居中

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:27 24 4
gpt4 key购买 nike

我试图让我的导航栏在我的页面上居中,导航栏的边缘在浏览器窗口的整个长度上。我想不通。我认为它与 float:left 个别导航元素有关。我希望这个导航栏在整个浏览器窗口中都是橙色背景,但实际的导航项要在页面上居中。我已经复制了下面的代码和下面的工作演示。


    <div id="nav-wrapper">
<div id="navmenu">

<ul class="nav" >
<li><a href="#">About</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>
<li><a href="#">Members & Groups</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>
<li><a href="#">Meetings & Events</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>

</ul>

<!-- hp navigation end -->
</div>
</div>

    #nav-wrapper {

width:100%;
background: #ff6633;
margin 0 auto;
}



#navmenu{

margin 0 auto;
width:100%;


}


#navmenu ul {
list-style-type: none;

padding: 0;
}




.nav li > a {
background: #ff6633;
color: white;
width: 137px;

}



.nav > li > a {
display: block;
height: 100%;
padding: 0px;
color: #000000;
text-decoration: none;
text-align: center;
line-height: 32px;
outline: none;
border-right: 1px solid #D6D3D3;

}

.nav > li:hover > a {
color:#333;


}


.nav > li {
padding: 0;
height: 30px;
font-family: Arial, Helvetica, sans-serif;
letter-spacing: -0.5px;
font-size: 14px;

}

.nav li {

float: left;
}


.nav li > ul {
position: absolute;
display: none;
border-bottom: 0;
width: 220px;
z-index: 9999;
}



.nav li > ul > li > a {
text-decoration: none;
color: #0f2992;
display: block;
padding:5px 3px 5px 10px;
text-indent:-7px;
}


.nav li:hover > ul {
display: block;
}

http://codepen.io/trevoray/pen/KwJPLO

最佳答案

#navmenu{

margin 0 auto;
width:100%;


}


#navmenu ul {
list-style-type: none;

padding: 0;
text-align:center
}




.nav li > a {
background: #ff6633;
color: white;
width: 137px;

}

.nav li > ul > li {
width:100%;display:inline-block
}

.nav > li > a {
display: block;
height: 100%;
padding: 0px;
color: #000000;
text-decoration: none;
text-align: center;
line-height: 32px;
outline: none;
border-right: 1px solid #D6D3D3;
width:100%;

}

.nav > li:hover > a {
color:#333;


}


.nav > li {
padding: 0;
height: 30px;
font-family: Arial, Helvetica, sans-serif;
letter-spacing: -0.5px;
font-size: 14px;
position: relative;
width: 32%;
}

.nav li {

display:inline-block
}


.nav li > ul {
position: absolute;
display: none;
border-bottom: 0;
width: 100%;
z-index: 9999;
list-style:none;
text-align: left !important;
}



.nav li > ul > li > a {
text-decoration: none;
color: #0f2992;
display: block;
padding:5px 3px 5px 10px;
text-indent:-7px;
width:100%;
box-sizing: border-box;
}


.nav li:hover > ul {
display: block;
}
<div id="nav-wrapper">
<div id="navmenu">

<ul class="nav" >
<li><a href="#">About</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>
<li><a href="#">Members & Groups</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>
<li><a href="#">Meetings & Events</a>
<ul>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>

</ul>
</li>

</ul>

<!-- hp navigation end -->
</div>
</div>

try this :http://jsfiddle.net/au07b2r3/3/
i remove float left from li ..and set display : inline-block

关于css - 无法让导航栏在页面上居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29211997/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com