Reputation: 1343
I am using Twitter Bootstrap 3 to build my new website. I want to place a button on the left side and a pagination on the right side.
<button type="button" class="btn btn-default pull-left">Default</button>
<ul class="pagination pull-right">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
My problem is that I am unable to align the both elements properly:
The pagination has a small offset.
What can i do to remove that offset?
Upvotes: 16
Views: 52069
Reputation: 61
`<div class="pagination justify-content-center pagination-large" id="pagination-demo">
`
justify-content-center will flex your pag to center
Upvotes: -1
Reputation: 3761
I would go for:
<div class="btn-toolbar" role="toolbar" style="margin: 0;">
<div class="btn-group">
<button type="button" class="btn btn-default">1</button>
<button type="button" class="btn btn-default">2</button>
</div>
<div class="btn-group pull-right">
<ul class="pagination" style="margin: 0;">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
</div>
</div>
if you replace the <ul><li....
with buttons , you not need to use style="margin: 0;
Example here: http://getbootstrap.com/components/#btn-groups-toolbar
Upvotes: 8
Reputation: 2842
Wrap a semantic descriptive class around your button and pagination, such as .navigation-bar and use this to target the margin on the .pagination:
.navigation-bar .pagination {
margin-top: 0;
}
You should never override a framework class directly, as it would apply across your entire code base. The alternative is to simply extend the .pagination class:
<ul class="pagination no-margin pull-right">
Upvotes: 16
Reputation:
You could set a width and use margins to centre it on the page. Also note for this solution to work you have to remove .pull-right
from the ul
Here is the HTML:
<button type="button" class="btn btn-default pull-left">Default</button>
<ul class="pagination pull-right">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
Here is the CSS:
.pagination {
display: block;
width: 232px;
margin: 0 auto;
background: #ccc;
}
Upvotes: 0
Reputation: 151
You can put it in a table & then apply margin top.
<table>
<tr>
<td>
<button type="button" class="btn btn-default pull-left">
Default</button>
</td>
<td>
<ul class="pagination pull-right">
<li><a href="#">«</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">»</a></li>
</ul>
</td>
</tr>
Upvotes: -1
Reputation: 1088
add this class to your ul and in your css:
.no-top-margin {
margin-top: 0;
}
or this to your button and css:
.add-top-margin {
margin-top: 20px;
}
Also I would recommend Googling and reading some beginner tutorials on using either Chrome Developer Tools or Firebug for firefox, especially if you are going to be doing more html/web development in the future :-).
Upvotes: 0
Reputation: 2126
Put the below styling in the ul element:
<ul style="margin-top:0;" class="pagination pull-right">
Upvotes: 2