Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place button group at the far right side of a header with Bootstrap

I've managed to place a button group at the far side of a header (H1/H2/H3). However, I don't know how to make the button float vertically in the middle. It just stays at the top. I tried using margin-top but since it's a fixed value it won't be dynamically placed in the middle.

Here's the screenshot:

enter image description here

Here's the code:

<div class="container">   <section>     <div class="page-header">       <h1 class="pull-left">         The header       </h1>       <div class="pull-right">         <div class="btn-group">           <button class="btn btn-primary">             Actions           </button>           <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">             <span class="caret"></span>           </button>           <ul class="dropdown-menu pull-right">             <li>               <a href="#">Action</a>             </li>             <li>               <a href="#">Another Action</a>             </li>           </ul>         </div>       </div>       <div class="clearfix"></div>     </div>     Contents   </section> </div> 

Thanks in advance.

jsFiddle: http://jsfiddle.net/aurorius/PKrUC/

like image 461
Amree Avatar asked Oct 30 '12 09:10

Amree


People also ask

How do I put the button on the right side of the header?

If you have multiple buttons that you want to align to the right using the class="ui-btn-right" in <a> will place all the buttons on top of each other. Instead you can just wrap a div around it and float to the right.

How do I move the button to the right side in Bootstrap?

Answer: Use the text-right Classtext-right on the containing element to right align your Bootstrap buttons within a block box or grid column. It will work in both Bootstrap 3 and 4 versions.

How do I center a group button in Bootstrap?

Answer: Use the text-center Class You can simply use the built-in class . text-center on the wrapper element to center align buttons or other inline elements in Bootstrap.


2 Answers

This how to get a button lined up with the header in Bootstrap 3.2, 3.3 without any additional CSS in case anyone is coming here from Google.

Option 1

http://jsfiddle.net/ypaL5nko/

<div class='page-header'>   <div class='btn-toolbar pull-right'>     <div class='btn-group'>       <button type='button' class='btn btn-primary'>Button Text</button>     </div>   </div>   <h2>Header Text</h2> </div> 

The button group is optional if you're only using a single button.

Option 2

http://jsfiddle.net/sLdnae3q/

<h1>   <span>Header Text</span>   <button class='btn btn-primary pull-right'>Button Text</button> </h1> <hr/> 
like image 133
johnsorrentino Avatar answered Sep 20 '22 11:09

johnsorrentino


Try this css code

.btn-group.my-class{   bottom: 15px;   position: relative;   top: 15px; } 

Dynamic header on H1/H2/H3 and may be H4

Demo: http://jsfiddle.net/PKrUC/2/

like image 32
Selvamani Avatar answered Sep 23 '22 11:09

Selvamani