简体   繁体   English

导航图标之间的间距相等

[英]Equal space between navigation icons

How to have facebook navigation like alignments in Bootstrap? 如何在Bootstrap中使Facebook导航像对齐方式?

Run the code in full page. 全页运行代码。

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"> <nav class="navbar navbar-expand-sm fixed-top" style="background-color: #ffdbae;"> <ul class="navbar-nav"> <li class="nav-item"><a href="http://localhost/mp/"><i class="fas fa-book-open" style="font-size:40px; color:#00CED1;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/post"><i class="fas fa-pen-fancy" style="font-size:40px; color:#fff;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/settings"><i class="fas fa-sliders-h" style="font-size:40px; color:#fff;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/profile"><i class="fas fa-user" style="font-size:40px; color:#fff;"></i></a></li> </ul> </nav> 

As facebook navigation icons have equal space between each other, how can I acheive it in my navigation? 由于facebook导航图标之间具有相等的间距,如何在导航中实现它?

Note : If the screen gets bigger/shorter it should auto adjust them self. 注意 :如果屏幕变大/变短,则应自行自动调整。

You can use flexbox to evenly space each nav item: 您可以使用flexbox均匀分隔每个导航项:

.navbar-nav {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

 .navbar-nav { display: flex; justify-content: space-between; width: 100%; } 
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"> <nav class="navbar navbar-expand-sm fixed-top" style="background-color: #ffdbae;"> <ul class="navbar-nav"> <li class="nav-item"><a href="http://localhost/mp/"><i class="fas fa-book-open" style="font-size:40px; color:#00CED1;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/post"><i class="fas fa-pen-fancy" style="font-size:40px; color:#fff;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/settings"><i class="fas fa-sliders-h" style="font-size:40px; color:#fff;"></i></a></li> <li class="nav-item"><a href="http://localhost/mp/profile"><i class="fas fa-user" style="font-size:40px; color:#fff;"></i></a></li> </ul> </nav> 

Simpler than I thought with no need to redefine the BS4 CSS. 比我想象的要简单,无需重新定义BS4 CSS。 I modified the navbar to use bs4 markup without the ul and li ...seems cleaner this way 我修改了导航栏以使用不带ulli bs4标记...似乎更清洁

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css"> <nav class="navbar navbar-expand-sm fixed-top" style="background-color: #ffdbae;"> <div class="navbar-nav w-100 nav-justified"> <a class="nav-item" href="http://localhost/mp/"><i class="fas fa-book-open" style="font-size:40px; color:#00CED1;"></i></a> <a class="nav-item" href="http://localhost/mp/post"><i class="fas fa-pen-fancy" style="font-size:40px; color:#fff;"></i></a> <a class="nav-item" href="http://localhost/mp/settings"><i class="fas fa-sliders-h" style="font-size:40px; color:#fff;"></i></a> <a class="nav-item" href="http://localhost/mp/profile"><i class="fas fa-user" style="font-size:40px; color:#fff;"></i></a> </div> </nav> 

You can do something like this: 您可以执行以下操作:

   .navbar-nav {
      display: flex;
    }
    .nav-item {
      flex: 1;
      text-align: center;
      margin: 5px;
    }

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

相关问题 在所有分辨率的两个图标之间添加空格 - Add space between the two icons for all resolutions d3中传说之间的平等空间 - Equal Space between the legends in d3 内联块列表,文本之间的空格相等。 - inline-block list with equal space between text. 导航栏中的水平图标 - Horizontal Icons In Navigation Bar 如何删除反应导航顶部栏中选项卡之间的空白 - How to remove white space between the tabs in react navigation top bar 在 Material-UI 抽屉中的顶部和底部图标之间留出空白空间 - Leave empty space between top and bottom icons in Material-UI Drawer 使用 Material-UI 图标进行导航 - Navigation with Material-UI Icons 覆盖布尔玛轮播中的导航图标 - Override navigation icons in bulma carousel 如何编写一个正则表达式命令来匹配多个分隔符,包括任意数量的空格,但不等号之间的空格? - how to write a regex command that match several dividers including any number of spaces, but not space(s) between equal sign? 使用 flex-wrap 包裹物品后,移除右侧的多余空间,同时保持物品之间的间距相等 - remove extra space on the right after the wrapping of items with flex-wrap, while maintaining equal spacing between items
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM