Scaling and Responsiveness in Bootstrap 4 Pagination

Currently utilizing the pagination feature in Bootstrap 4 as outlined here.

While I am able to smoothly navigate between my pages, I have noticed that the navigation buttons do not adjust properly to changes in screen size. For instance, with a total of 16 pages, on mobile devices or when resizing my browser to a smaller width, only page buttons for pages 4 through 14 are visible. I was under the impression that the buttons would resize accordingly as the page width decreased, but this is not the case.

Specifics:

  • The necessary viewport meta tag for Bootstrap has been included.
  • A container div is used to house my pagination list.
  • The Bootstrap CDN is correctly loaded.
  • I have omitted any code samples as my implementation mirrors the Bootstrap example precisely.

Thank you for your assistance :)

Answer №1

To handle various scenarios, one handy trick is to use the combination of the .flex-wrap and .pagination classes to make your list break into multiple rows on smaller devices.

<ul class="pagination flex-wrap">
    <li class="page-item"><a class="page-link" href="#">A</a></li>
    <li class="page-item"><a class="page-link" href="#">B</a></li>
    ...
    <li class="page-item"><a class="page-link" href="#">Z</a></li>
</ul>

This approach comes in handy when there are not too many pages to display, allowing all of them to be visible without the need for scrolling or any other action.

Answer №2

Bootstrap's Pagination component lacks intelligent, responsive behaviors inherent in the Grid system. Therefore, the behavior you are describing is expected.

The challenge arises in how to tackle this limitation. Scaling down the buttons, as you propose, may seem like a good idea initially; however, when dealing with a high number of pages – say 100 pages – fitting all buttons on a single line would result in excessively small buttons.

Bootstrap's Pagination component offers a couple of built-in approaches to address this issue:

  • Show a set number of page numbers along with Prev and Next buttons.
  • The above approach, but include a ... spacer to indicate additional pages.

Alternatively, you can modify the behavior of the Pagination component itself using a simple wrapper class: .table-responsive

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">

<nav aria-label="Page navigation example" class="table-responsive mb-2">
  <ul class="pagination mb-0">
    <li class="page-item disabled"><a class="page-link" href="#" tabindex="-1">Previous</a></li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item"><a class="page-link" href="#">4</a></li>
    <li class="page-item"><a class="page-link" href="#">5</a></li>
    <li class="page-item"><a class="page-link" href="#">6</a></li>
    <li class="page-item"><a class="page-link" href="#">7</a></li>
    <li class="page-item"><a class="page-link" href="#">8</a></li>
    <li class="page-item"><a class="page-link" href="#">9</a></li>
    <li class="page-item"><a class="page-link" href="#">10</a></li>
[...]

The .table-responsive class, typically used for tables to enable horizontal scrolling beyond screen width, also proves useful for accommodating various pagination options effectively within Bootstrap.

However, it must be acknowledged that this setup results in poor user experience. This explains why many pagination patterns align with the aforementioned bullet points.

Answer №3

If you're curious, I implemented a method on my web application where I enclose the <ul> element within a navigation tag using a CSS class to create a horizontal scrollbar.

<nav class="HORIZONTAL_SCROLL_NAV">

Check out this demo: https://jsfiddle.net/JonathanParentLevesque/z4gL1wkb/5/

https://i.sstatic.net/YFPvn.jpg

The basic CSS needed for this implementation is:

.HORIZONTAL_SCROLL_NAV {

    -webkit-overflow-scrolling: touch;

    overflow-x: auto;
    overflow-y: hidden; 
}

.HORIZONTAL_SCROLL_NAV>ul {

    margin: 0 auto;
}

You can customize the scrollbar with additional CSS properties (supported by certain browsers: https://caniuse.com/#feat=css-scrollbar):

.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar {

    height: 10px;
}

.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar-track {

    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);

    -webkit-border-radius: 10px;
    border-radius: 10px;
}

.HORIZONTAL_SCROLL_NAV::-webkit-scrollbar-thumb {

    -webkit-border-radius: 10px;
    border-radius: 10px;

    background: rgba(255, 0, 0, 0.8);

    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5); 
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
}

Answer №4

You have the option to utilize .pagination-sm .pagination-lg

   <nav aria-label="...">
  <ul class="pagination pagination-sm">
    <li class="page-item disabled">
      <a class="page-link" href="#" tabindex="-1">1</a>
    </li>
    <li class="page-item"><a class="page-link" href="#">2</a></li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
  </ul>
</nav>

Answer №5

Here are some enhanced suggestions for Dario Muñoz's answer:

<ul class="pagination flex-wrap">
    <li class="page-item"><a class="page-link" href="#">A</a></li>
    <li class="page-item"><a class="page-link" href="#">B</a></li>
    ...
    <li class="page-item"><a class="page-link" href="#">Z</a></li>
</ul>

For a more polished pagination display, don't forget to update the scss accordingly: Although the example is hardcoded, consider retrieving the variables from Bootstrap's variables file.

.flex-wrap.pagination{
  margin-left: 3px;
  .page-item {
    margin-bottom: 5px;
  }

  .page-item:first-child{
    margin-left: -3px;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to apply multiple text shadows to a single piece of text using the jQuery ".css()" method?

Is it possible to create multiple text shadows for a single piece of text using the jQuery ".css()" method? I'm currently working on animating the title of a page on my website, which includes adding a 3D effect with multiple shadows. I also want to ...

Is there a way to organize a specific column based on user selection from a drop down menu on the client side?

When selecting Timestamp from the drop-down menu, I expect the TimeStamp to be sorted in either ascending or descending order. Similarly, if I choose Host, the Host should be sorted accordingly. Despite using the Tablesorter plugin, sorting doesn't s ...

What is the best way to retrieve a modified HTML input field in CodeIgniter PHP?

I am using a CodeIgniter PHP website with a form for users to add and edit products. The editing process is functioning correctly, here is the code for editing a product: View: <form action="" method="post" enctype="multipart/form-data"> < ...

Scan across a lineup of pictures

I am looking to showcase a series of images in a horizontal alignment, but I want to avoid overloading the screen width. My goal is to allow users to navigate through the images using their mouse - when they move right within the image container, I want t ...

Creating specific CSS classes for individual slides in a basic slider framework

So, I have a rather simple slider that is created using only CSS. Each slide has unique labels for navigation buttons. The main question here is: how can I dynamically add or remove classes to specific items on the slide only when that particular slide is ...

Tips on formatting text as bold or italic when tweeting from my website to our Twitter account

Currently, I am utilizing the Twitter OAuth library in conjunction with PHP to publish a tweet from my website directly to my Twitter account. My main objective is to highlight some text while posting, however, I have not been successful in identifying t ...

What is the best method for populating a text area in Pharo with HTML content?

When logging in through Pharo using an HTML form, you can utilize the method of Znclient called formAt:add: followed by a post. I'm interested to know how I can fill a textArea in an HTML form and then make a post request. Is there a specific method f ...

Ways to turn off .removeClass()

Encountering an issue with jquery-2.1.4.js. Upon integrating a layerslider into my website, the script modified div classes. Attempted using older versions of the script without success. Currently have classes as follows: <a href="#" class="col-md-3 ...

Ways to apply CSS styling to a specific SVG element without affecting others?

Originally, I had created a single bar chart using SVG: bars.append("rect") .attr("x", midX) .attr("y", 0) .attr("width", function(d) { return x(d.values[0].value); }) .attr("height", y.bandwidth()) .classed("highlight", function(d) { retu ...

Concealing elements with HTML, CSS, and JavaScript by setting the display

Issue arose when I set my id="Gabel" display to none, resulting in distorted formatting. Any suggestions for correcting this? Desired outcome is to show display id="Gabel" upon clicking the image on the main page. Here are relevant co ...

Tips for assigning a class to an Angular accordion header when the panel is in the open state

I am currently utilizing the Angular UI Bootstrap accordion feature, which can be found here. <div ng-controller="AccordionDemoCtrl"> <div accordion close-others="oneAtATime"> <div accordion-group heading ...

Change the color of the text in a shiny dashboard

While exploring shiny dashboard, I came across this link that explains how to modify colors in the sidebar and header. However, I'm struggling to change the font color for sidebar items. The default white font color becomes unreadable when using light ...

"Enhancing User Experience with AngularJS by Dynamically Modifying and Refresh

I'm currently attempting to dynamically add HTML elements using JavaScript with a directive: document.getElementsByClassName("day-grid")[0].innerHTML = "<div ng-uc-day-event></div>"; or var ele = document.createElement("div"); ele.setAttr ...

Centering White in an Accordion with JQuery

Can anyone explain the mysterious presence of a large white space in the center of my accordion content? Despite having the correct .css settings, there seems to be an unexplainable white space disrupting the layout. #accordion .ui-accordion-content { ...

Enhancing the Search Form Minimum Width in Bootstrap 4 Navbar

Looking for a way to create a search form with a width of 100% and a minimum width within a Bootstrap 4 navbar? Check out my code snippet here. <nav class="navbar navbar-expand-md navbar-light bg-faded"> <a href="/" class="navbar-brand">Brand& ...

Timer countdown: Looking for a countdown timer that will reset to 3:00 automatically each time it reaches 0 minutes, and can do so

Seeking a continuous countdown timer that starts from 03:00 and counts down to 0:00, then automatically resets back to 03:00, in an infinite loop. The condition is that no one should be able to manually stop this logic. After researching, I found a Ja ...

Traversing tables with JQuery's nextUntil function

I have a calendar table where I need to highlight the range from the pickup date, maybe 10 Feb, to the set date of 20 Feb. <tr class="rd-days-row"> <td class="rd-day-body rd-day-disabled">09</td> <td class="rd-day-body">10& ...

Image Handpicked by JCrop User

Successfully implemented JCrop example code for selecting an area on an image with a preview and getting coordinates. However, the challenge lies in allowing users to select an image from their file system, display it in the browser, and perform the afore ...

Is it possible to fetch all the content contained within each set of <p> and </p> tags within a specific ID?

I've been trying to extract text between two specific <p> tags in HTML, but my code is only returning the text between a single tag. Here's what I have so far: > var myHTMLString = try String(contentsOf: myURL, encoding: .as ...

Creating a horizontal layout for list items that are responsive using CSS

My website has a "Featured" section with 3 equally sized elements displayed horizontally. I want to make the webpage responsive by using percentage widths, but when I resize the window to less than the list width, the items stack on top of each other. Che ...