html - 导航栏对齐 <ul>

标签 html css bootstrap-4

我需要垂直对齐导航栏中间的栏。我设置了 align-items: center for bar 但它只对齐登录按钮。如您所见,它略高于中间位置。

nav a{
color:white;
}
nav{
    justify-content: space-between;
    align-items: center;
    background-color: brown;

}
nav ul{
    list-style: none;
    padding: 0;
    display: flex;
    align-items: center;
    background-color: black;

}
nav ul li a{
    padding: 1rem 0;
    margin: 0 0.5rem;
    position: relative;
    font-size: 14px;
    font-weight: bold;
}
.container{
  background-color: green;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="container" >
            <nav class="d-flex flex-row">
                <h1 class="sling"><a href="index.html">Sling</a></h1>
                <ul>
                    <li><a href="#">Home</a></li>
                    <li><a href="#">Features</a></li>
                    <li><a href="#">Pricing</a></li>
                    <li><a href="#">Testimonial</a></li>
                    <li><a href="#">Download</a></li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Contact us</a></li>
                </ul>
                <button type="button" class="signin">Sign in</button>
            </nav>
        </div>

正确的。

最佳答案

在 UL 上使用 mb-0 清除底部边距。

    <nav class="d-flex flex-row align-items-center">
        <h1 class="sling"><a href="index.html">Sling</a></h1>
        <ul class="mb-0">
            <li><a href="#">Home</a></li>
            <li><a href="#">Features</a></li>
            <li><a href="#">Pricing</a></li>
            <li><a href="#">Testimonial</a></li>
            <li><a href="#">Download</a></li>
            <li><a href="#">News</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>
        <button type="button" class="signin">Sign in</button>
    </nav>

https://www.codeply.com/go/Fa33cYUN52

关于html - 导航栏对齐 <ul>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55188940/

相关文章:

javascript - 从多个表单中选择的下拉列表

css - IE10 没有在 JSFiddle 之外的 HTML5 的页眉/页脚/导航/主要元素上应用 CSS 样式。 HTML5 怪癖模式触发?

css - 整页设计 : How to force a Div to stop expanding at the bottom of the page

html - 如何使用 CSS 将文本居中放置在 div 元素中

html - Bootstrap 4崩溃链接aria-expanded =“true”不起作用

image - Vue Bootstrap img 不从 Assets 文件夹中显示

html - "Look at"KML 地标的链接列表

html - 导航不会显示内联?

html - 如何在元素聚焦时动态更改 sass 属性?

javascript - 引导冲突汉堡菜单显示