gpt4 book ai didi

html - 在导航容器内居中导航元素

转载 作者:行者123 更新时间:2023-11-28 01:10:50 25 4
gpt4 key购买 nike

在我的元素中,我很难将导航项的内容置于导航容器内。我不能在 ul>li 项上留边距,因为它不适用于不同的分辨率。也许我需要一些百分比,但我试过了但没有任何效果。预期的结果是这样的 enter image description here

你可以找到一个小演示 here

非常感谢,安德烈亚。

.header-nav-fixed-down {
height: 60px;
padding: 20px;
background-color: #2c3642;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.3);
}

.divider {
width: 1px;
height: 30px;
background-color: #000000;
}

div#navbarCollapse ul li a{
color: grey !important;
}
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 4 Navbar with hover multi dropdown</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

<link href="css/bootstrap-4-hover-navbar.css" rel="stylesheet">



</head>
<body>

<nav class="navbar navbar-expand-md fixed-down header-nav-fixed-down ">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav m-auto">
<li class=" nav-item ">
<a href="#">ItemA</a>
</li>
<li role="separator" class="divider m-auto"></li>
</ul>
<ul class="navbar-nav m-auto">
<li class="nav-item">
<a href="#">ItemB.1</a>
</li>
<li class="nav-item">
<a href="#">ItemB.2</a>
</li>
<li class="nav-item">
<a href="#">ItemB.3</a>
</li>
<li role="separator" class="divider"></li>
</ul>

<ul class="navbar-nav m-auto">
<li class="nav-item">
<a href="#">ItemB.1</a>
</li>
<li class="nav-item">
<a href="#">ItemB.2</a>
</li>
<li class="nav-item">
<a href="#">ItemB.3</a>
</li>
<li role="separator" class="divider"></li>
</ul>

<ul class="navbar-nav m-auto">
<li class="nav-item">
<a href="#">ItemD</a>
</li>

<li role="separator" class="divider"></li>
</ul>
<ul class="navbar-nav m-auto">
<li class="nav-item">
<a href="#">ItemE1</a>
</li>
<li class="nav-item">
<a href="#">ItemE2</a>
</li>
<li role="separator" class="divider"></li>
</ul>
<ul class="navbar-nav m-auto">
<li class="nav-item ">
<a href="#">ItemF1</a>
</li>
<li class="nav-item ">
<a href="#">ItemF2</a>
</li>
<li role="separator" class="divider"></li>
</ul>
</div>
</nav>








<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>

<script src="js/bootstrap-4-hover-navbar.js"></script>


</body></html>

最佳答案

您可以将 Flexbox 用于导航容器。这将允许导航容器内的元素“flex ”并让您能够控制它们的方向(垂直、水平)和它们的一般位置(开始、中心、结束)。最好的部分是它是响应式的,所以当屏幕尺寸改变时,您的 child (在导航中列出元素)将 flex 并适应他们周围的可用空间。您可以尝试以下方法开始。

.navigation {
display: flex;
justify-content: space-evenly;
align-items: center;
}

关于html - 在导航容器内居中导航元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52117438/

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