Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Make Responsive Bootstrap 3 Pagination

This: enter image description here

Turns in to this on smaller viewports:

enter image description here

I think it looks yucky and it takes up a lot of space too.

This is standard pagination html:

<div class="container">
       <div class="text-center">
          <ul class="pagination pagination-lg">
             <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 class="disabled"><span>...</span></li>
             <li><a href="#">12</a></li>
             <li><a href="#">13</a></li>
             <li><a href="#">14</a></li>
             <li><a href="#">15</a></li>
             <li><a href="#">16</a></li>
             <li><a href="#">&raquo;</a></li>
          </ul>
       </div>
    </div>

Now, I could use smaller versions with the classes they provide, however everything -- no matter what -- should be friendly for fat fingers because some touch devices just as big as desktop devices.

like image 285
Christina Avatar asked Sep 14 '14 21:09

Christina


People also ask

How do I center my bootstrap 3 pagination?

With Bootstrap 3, you would have to wrap the <ul class="pagination">... </ul> inside a <div class="text-center"></div> .

How can we customize links to pagination in bootstrap?

Add the list items with class name page-items. In addition, as pages likely have more than one such navigation section, So provide a descriptive aria-label for the <nav> to reflect its purpose. To customize the links for each page, just remove “#” and add the desired link.

How pagination is used in bootstrap?

Pagination is built with list HTML elements so screen readers can announce the number of available links. Use a wrapping <nav> element to identify it as a navigation section to screen readers and other assistive technologies.

Which of the following class in bootstrap is used to create basic pagination?

The . pagination class is used to specify pagination on a list group.


3 Answers

In my opinion toggling the pagination is a helper but not the final solution. I found a bootstrap plugin that does exactly what I expect pagination to do at smaller screen sizes - it shrinks the number of paginated li chunks to match the screen width like this:

wide screen sizemedium screen sizesmall screen size

rPage - responsive bootstrap3 pagination plugin

like image 114
Hexodus Avatar answered Oct 17 '22 04:10

Hexodus


You can use class="hidden-xs":

Normal

< 1 2 3 4 [5] 6 7 8 9 10 >

Small

< 4 [5] 6 >

Example in php

if($number != $page) { echo ' class="hidden-xs" '; }
like image 22
Carles Campi Areny Avatar answered Oct 17 '22 04:10

Carles Campi Areny


DEMO: http://jsbin.com/cotopu/1

enter image description here

CSS:

/* pagination-responsive */
@media (min-width:0px) and (max-width:650px) { 
    .toggle-pagination {
        display: block
    }
    .toggle-pagination.active i:before {
        content: '\2212'
    }
    .pagination-responsive {
        width: 100%;
        margin-top: 10px;
        display: none;
    }
    .pagination-responsive > li > a,
    .pagination-responsive > li > span {
        width: 100%;
        margin: 0;
        line-height: 40px;
        padding: 0;
        border-radius: 0px!important;
    }
    .pagination-responsive > li {
        float: left;
        width: 20%;
        margin-top: -1px;
        text-align: center;
    }
}
@media (max-width:480px) { 
    .pagination-responsive > li {
        width: 33%
    }
}
@media (max-width:320px) { 
    .pagination-responsive > li {
        width: 50%
    }
}
@media (min-width:651px) { 
    .toggle-pagination {
        display: none
    }
    .pagination-responsive {
        display: inline-block!important
    }
}

HTML:

<div class="container">
   <div class="text-center">
     <a class="btn btn-default btn-block toggle-pagination"><i class="glyphicon glyphicon-plus"></i> Toggle Pagination</a>
      <ul class="pagination pagination-responsive pagination-lg">
         <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 class="disabled"><span>...</span></li>
         <li><a href="#">12</a></li>
         <li><a href="#">13</a></li>
         <li><a href="#">14</a></li>
         <li><a href="#">15</a></li>
         <li><a href="#">16</a></li>
         <li><a href="#">&raquo;</a></li>
      </ul>
   </div>
</div>

jQuery:

$(document).ready(function() {
// show-pagination
    $('.toggle-pagination').click(function(f) {
        $(this).next('.pagination-responsive').slideToggle();
        $(this).toggleClass('active');
        f.preventDefault()
    });
});
like image 6
Christina Avatar answered Oct 17 '22 03:10

Christina