This:
Turns in to this on smaller viewports:
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="#">«</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="#">»</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.
With Bootstrap 3, you would have to wrap the <ul class="pagination">... </ul> inside a <div class="text-center"></div> .
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.
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.
The . pagination class is used to specify pagination on a list group.
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:
rPage - responsive bootstrap3 pagination plugin
You can use class="hidden-xs"
:
< 1 2 3 4 [5] 6 7 8 9 10 >
< 4 [5] 6 >
if($number != $page) { echo ' class="hidden-xs" '; }
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="#">«</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="#">»</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()
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With