简体   繁体   中英

Bootstrap spacing of links on navbar

I'm looking to add a bit of spacing between my username and logout button as well as my login and signup button.

I've tried adding spaces (doesn't do anything) and I've also tried using list items and inserting an empty paragraph tag. What can I do to add two or three horizontal spaces?

 <ul class="nav navbar-nav navbar-right">
   <div style="margin-right: 10px; margin-left: 15px; margin-top: 15px; margin-bottom: 5px;"  class="container-fluid">
        {% if session.logged_in %}
         <a href="/dashboard/"> Welcome {{session['username']}}   </a>
         <a href="/logout/"><span class="glyphicon glyphicon-log-out"></span> Logout </a>
        {% else %}
        <a href="/login/"><span class="glyphicon glyphicon-log-in"></span> Login </a>
        <a href="/register/"><span class="glyphicon glyphicon-pencil"></span> Sign up</a>
        {% endif %}
   </div>
 </ul> 

These items are wrapped in

 <div id="navbar" class="collapse navbar-collapse">

along with my other links on the left side.

Here's a picture of what I have now: Current

I think you should apply a display: inline-block; or display: block; to <a></a> elements and then you can set the margins. That should do the work.

Or you can use <div></div> as their parent tag and then apply the margins to them. Just like that:

<div class="sample"><a></a></div>

And CSS:

sample {display: 
  inline-block;
}

To achieve expected result , use below two options

Option1:

Use unordered list tags ul , li

 <ul class="nav navbar-nav navbar-right">
      <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
      <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
    </ul>

Option 2:

Use padding for the anchor tag with the existing code

<div class="row nav navbar-nav navbar-right test">
  <a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a>
    </div>

CSS:

.test a{
  padding:10px;
}

For comparison, I have used both options in one codepen, please check it once

https://codepen.io/nagasai/pen/aypdXZ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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