简体   繁体   English

在Bootstrap 4中将导航栏品牌和链接与页面内容对齐

[英]Align navbar brand and links with page content in Bootstrap 4

I have a page designed in Bootstrap 4 which has one column in the center of the screen. 我有一个在Bootstrap 4中设计的页面,该页面在屏幕中央有一列。 How can I make my navbar-brand followed by nav-links be aligned so that the brand is aligned with the text on the page? 如何使我的导航栏品牌及其后的导航链接对齐,以使品牌与页面上的文字对齐? The links should follow immediately to the right after the brand. 链接应紧跟品牌之后的右侧。

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> <nav class="navbar fixed-top navbar-expand-md navbar-default"> <div class="navbar-brand mx-auto" style="font-size:35"> <b><a href="#" style="color:#DCDCDC; padding-left:0"> Grigory Yaroslavtsev</a> <font style="color:#DCDCDC">@</font><a href="http://caml.indiana.edu" style="color:#DCDCDC">IU CAML</a></b> </div> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="collapsibleNavbar"> <ul class="navbar-nav mx-auto"> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#papers">Papers</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#talks">Talks</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#teaching">Teaching</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#personal">Personal</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#links">Links</a> </li> </ul> </div> </nav> 

Edit-2. 编辑-2。 Adding the contents of the nav inside a div with class of container is what you're looking for. 您正在寻找的是在具有类容器的div中添加导航的内容。 and using that you would put the remaining content inside another div with class container. 并使用它会将剩余的内容放入带有类容器的另一个div中。 Hope this solves it all. 希望这能解决所有问题。 Edit- I thought you wanted the side links all the way to the right. 编辑-我认为您一直想要右侧的侧面链接。 This should be what you wanted. 这应该是您想要的。

Remove the mx-auto classes and add .justify-content-end to the navbar-collapse 删除mx-auto类,然后将.justify-content-end添加到navbar-collapse

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" /> <nav class="navbar fixed-top navbar-expand-md navbar-default"> <div class="container"> <div class="navbar-brand" style="font-size:35"> <b><a href="#" style="color:#DCDCDC; padding-left:0"> Grigory Yaroslavtsev</a> <font style="color:#DCDCDC">@</font><a href="http://caml.indiana.edu" style="color:#DCDCDC">IU CAML</a></b> </div> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="collapsibleNavbar"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#papers">Papers</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#talks">Talks</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#teaching">Teaching</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#personal">Personal</a> </li> <li class="nav-item"> <a class="nav-link" style="font-size:25; color:#DCDCDC" target="_self" href="#links">Links</a> </li> </ul> </div> </div> </nav> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM