gpt4 book ai didi

html - css - Bootstrap - 在导航栏中将表单与表单控制 input-sm 垂直对齐

转载 作者:太空宇宙 更新时间:2023-11-03 22:52:46 27 4
gpt4 key购买 nike

我似乎无法将表单与放置在导航栏中的“input-sm”垂直对齐。如果表单的输入与导航栏的高度不同,则它们看起来是顶部对齐的。我希望有一种方法可以在不手动调整填充或边距顶部的情况下执行此操作。有什么想法吗?

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

<head>
<meta charset="utf-8">
<title>Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
<header>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li class="active">
<a href="#"><span class="glyphicon glyphicon-home"></span> Home</a>
</li>
<li>
<a href="#"><span class="glyphicon glyphicon-info-sign"></span> About</a>
</li>
<li>
<a href="#"><span class="glyphicon glyphicon-envelope"></span> Contact</a>
</li>
</ul>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<input type="email" class="form-control input-sm" name="email" placeholder="Email">
</div>
<div class="form-group">
<input type="password" class="form-control input-sm" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary btn-sm">Sign In</button>
</form>
</div>
</div>
</div>
</header>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>


</html>

enter image description here它看起来并不太糟糕,我只是想弄清楚如何去做!

最佳答案

最简单的做法是按照您提到的那样调整边距。 Bootstrap 就是这样做的。

.navbar-form {
margin-top: 10px;
margin-bottom: 10px;
}

如果可以的话,第二个最简单的方法是使用 flexbox

.navbar-form {
display: flex;
align-items: center;
}
/* Items will butt up next to each other using flexbox so the inline
spacing that existed before will be gone. So we replicate it. */
.navbar-form > .form-group {
margin-right: 0.25rem;
}

关于html - css - Bootstrap - 在导航栏中将表单与表单控制 input-sm 垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39412903/

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