gpt4 book ai didi

jquery - Bootstrap Horizo​​ntal NavBar 跨度页面宽度

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:34 25 4
gpt4 key购买 nike

如何让水平导航栏占据页面宽度的 80%?

我的导航栏是这样设置的:

<div class="navbar navbar-default navbar-centered" role="navigation">
<ul class="nav navbar-nav">
<li><a class="navbar-button" role="button" href="#home">HOME</a></li>
<li><a class="navbar-button" role="button" href="#about">ABOUT</a></li>
<li><a class="navbar-button" role="button" href="#gallery">GALLERY</a></li>
<li><a class="navbar-button" role="button" href="#products">PRODUCTS</a></li>
<li><a class="navbar-button" role="button" href="#contact">CONTACT</a></li>
</ul>
</div>

当页面调整大小时,它水平居中,元素垂直堆叠。

但是,这些元素都聚集在页面中心附近,我希望它们散开。

我的 CSS 看起来像这样:

.navbar-button {
background-color: white;
color: inherit;
border: 3px solid blue;
border-radius: 0px;
}

.navbar {
background-color: green;
border: 0px;
padding: 0px;
}

/*Center the navbar elements when collapsed*/
.navbar .navbar-collapse {
text-align: center;
}

@media (min-width: 768px) {
.navbar-centered .navbar-nav {
float: none;
text-align: center;
}
.navbar-centered .navbar-nav > li {
float: none;
}
.navbar-centered .nav > li {
display: inline;
}
.navbar-centered .nav > li > a {
display: inline-block;
}
}

最佳答案

将此行添加到 CSS:

@media(max-width:767px) {
.navbar {
max-width:80%;
margin:auto;
/* float: left; or right as you want and then remove margin: auto*/
}

}
@media(min-width:768px) {
/* add here also if you want to have big menu 80% width */
}
@media(min-width:992px) {
/* add here also if you want to have big menu 80% width */
}
@media(min-width:1200px) {
/* add here also if you want to have big menu 80% width */
}

参见 DEMO

关于jquery - Bootstrap Horizo​​ntal NavBar 跨度页面宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36241511/

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