简体   繁体   中英

Bootstrap alignment of button and pagination

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="#">&laquo;</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="#">&raquo;</a></li>
 </ul>

My problem is that I am unable to align the both elements properly:

http://bootply.com/91723

The pagination has a small offset.

What can i do to remove that offset?

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;
    }

http://bootply.com/91736

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"> 

Try adding ths:-

.pagination {
margin: 0px !important;
}

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>

http://www.bootply.com/116457

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

将下面的样式放在ul元素中:

<ul style="margin-top:0;" class="pagination pull-right">

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 :-).

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;
}

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="#">&laquo;</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="#">&raquo;</a></li>
        </ul>
    </td>
</tr>

`<div class="pagination justify-content-center pagination-large" id="pagination-demo">                   

`

justify-content-center will flex your pag to center

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