gpt4 book ai didi

html - Bootstrap 导航栏垂直居中水平?

转载 作者:行者123 更新时间:2023-11-28 02:49:59 25 4
gpt4 key购买 nike

是否可以将导航栏垂直和水平居中?

/**
* Logo.
*/
.button-logo {
font-family: 'Monoton', cursive;
font-weight:normal;
font-size:40px;
font-weight: 300;
line-height: 40px;
letter-spacing: 1px;
}

.button-logo:hover {
text-decoration: none;
}

.button-logo span {
display: block;
clear:both;
color: #000;
}

/**
* Centerise the logo.
*/
.navbar-header {
float: left;
text-align: center;
width: 100%;
}

.navbar-brand {
float:none;
}

/**
* Centerise the navbar.
*/
.navbar .navbar-nav {
display: inline-block;
float: none;
}

.navbar .navbar-collapse {
text-align: center;
}

/**
* Remove default background, radius, etc.
*/
.navbar {
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;

border: 0;
background: none;
box-shadow: none;
margin-bottom: 0;
}

.navbar-default .navbar-nav > li > a {
font-family: 'Monoton', cursive;
font-size: 25px;
letter-spacing: 2px;
color: #000;
color: rgba(0, 0, 0, 0.5);
padding-bottom: 0 !important;
}

.navbar-default .navbar-nav > li > a:hover {
color: #000;
}

.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
background: none;
background: none;
box-shadow: none;
color: #000;
}
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">

<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="offcanvas" data-target=".navmenu" data-canvas="body">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand button-logo" href="#">
<span>brand</span>
<span>brand</span>
<span>brand</span>
</a>
</div>

<div id="navbar" class="navbar-collapse collapse">

<!-- menu-box -->
<div class="menu-box">
<ul class="nav navbar-nav">
<li class="active"><a href="home.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</div>
<!-- menu-box -->

</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>

但这只会使导航栏水平居中而不是垂直。

有什么想法吗?

jsfiddle

最佳答案

要将导航栏放在屏幕中央,您只需添加

nav {
position: fixed;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

https://jsfiddle.net/anpvtaxu/1/

关于html - Bootstrap 导航栏垂直居中水平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39747210/

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