Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one right-justify bootstrap pills with css

I have a header with three sections, left, middle and right. I cant seem to come up with the proper css to make the column on the right (with 'email history' and 'back to list') float to the right side of the column. How can anyone tell me how this is done? Any help is appreciated.

<div class="col-sm-5" style="text-align:left">
    <button type="submit" class="btn btn-primary btn-lg navbar-btn">Save Contact</button>
</div>
<div class="col-sm-2" style="text-align:center">
   <h2 class="branding">Edit Contact</h2>
</div>
<div class="col-sm-5">
   <ul class="nav nav-pills">
      <li class="active"><a href="/GoHistory">Email History</a></li>
      <li class="active"><a href="/email_marketing/contact-list">Back To List</a></li>
   </ul>
</div>
like image 369
user2789697 Avatar asked Apr 30 '14 15:04

user2789697


People also ask

What are pills in bootstrap?

Bootstrap tabs separate data in the same wrappers but different panes. Pills are components placed in pages to speed up browsing. Also, the first step of adding links inside navbar is to apply <ul> element together with class="navbar-nav".

How do I make bootstrap tab active?

You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-toggle="tab" or data-toggle="pill" on an element. Adding the nav and nav-tabs classes to the tab ul will apply the Bootstrap tab styling, while adding the nav and nav-pills classes will apply pill styling.


2 Answers

NOTE: The answer below is valid for Bootstrap 2 and 3; in Bootstrap 4 the equivalent class is float-right, and viewport-specific float classes are also available.


The easiest option is to add the class pull-right to the ul element. This will float the pills to the right.

Sidenote: you can replace those inline styles with the helper classes text-left (which is often redundant) and text-center.

Here's a bootply example: http://www.bootply.com/134139

like image 179
nthall Avatar answered Oct 12 '22 15:10

nthall


Need to overwrite some Bootstrap styling...

You'll need to remove the float on the list items and set it to display:inline-block. Then for the unordered-list element, add text-align:left.

Here's the CSS:

ul.nav.nav-pills {
    text-align: right;
}

.nav-pills>li {
    float: none;
    display: inline-block;
}

Enjoy!

like image 45
Megaroeny Avatar answered Oct 12 '22 16:10

Megaroeny