gpt4 book ai didi

html - Bootstrap Navbar 内容不居中

转载 作者:行者123 更新时间:2023-11-28 16:25:47 24 4
gpt4 key购买 nike

我对 bootstrap 和 html/css 比较陌生,到目前为止我相处得很好。我一直试图做的是将导航栏的高度增加到 80px。我的问题是,现在我无法让导航栏的内容居中,它们太高了。

看起来像这样:https://gyazo.com/4ba22961033e9bafa13aac44a50de3f6

谢谢 :)

这是我的整个 CSS 代码:

* {
box-sizing: border-box;
}

body {
background-color:#f6f6f6;
background-image: url("img/bg.png");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center center;
background-size:cover;
overflow-x:hidden;
overflow-y:scroll;
margin:0;
padding:0!important;
}

.navbar {
position: relative;
border:1px solid transparent;
min-height: 80px;
border-top: 0;
border-bottom:1px solid #e7e7e7;
margin-bottom:0;
z-index: 100;
}

.navbar-default {
height: 80px;
}

.navbar-brand {
float:left;
font-size:18px;
line-height:80px;
height:80px;
padding:0 15px;
}

.navbar-toggle {
margin-top: 23px;
padding: 9px 10px !important;
}


.navbar-nav > li > a {
height: 80px;
padding-top:10px;
padding-bottom:10px;
line-height:20px;
border-left: 1px solid #e7e7e7;
}

.navbar-left {
float:left!important;
}

.navbar-right {
float:right!important;
margin-right:-15px;
}

.navbar-nav>li>.dropdown-menu {
margin-top:0;
border-top-right-radius:0;
border-top-left-radius:0;
}

HTML:

<!DOCTYPE html>
<html lang="en">

<head>

<!-- Bootstrap required meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Links to stylesheets and scripts -->
<link href="style.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<title>Test</title>

</head>

<body>

<!-- NavBar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Leaderboards</a></li>
<li><a href="#">Support</a></li>

<li class="dropdown">
<a class "dropdown-toggle" data-toggle="dropdown" href="#">(username&pp)
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Settings</a></li>
<li><a href="#">Statistics</a></li>
<li><a href="#">History</a></li>
<li><a href="#">Logout</a></li>

</ul>
</li>

</ul>
</div>
</nav>

</body>

</html>

最佳答案

尝试在 .navbar-nav > li > a CSS block 中添加以下 flex 属性:

display: flex;
align-items: center;

所以 .navbar-nav > li > a block 现在应该是这样的:

.navbar-nav > li > a {
display: flex;
align-items: center;
height: 80px;
padding-top: 10px;
padding-bottom: 10px;
line-height: 20px;
border-left: 1px solid #e7e7e7;
}

CodePen Demo

关于html - Bootstrap Navbar 内容不居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45128302/

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