Bootstrap 4 is a popular front-end programming framework for creating responsive, mobile-first websites. It provides various CSS and JavaScript elements such as navigation bars, forms, buttons, modals, etc. that may be used to quickly build a website with a modern and beautiful look.
Pagination alignment in Bootstrap 4 refers to the way the pagination components of a web page are positioned. Pagination is usually centered, however. The justify-content-* classes allow left or right alignment.
There are many possible ways to align pagination in Bootstrap 4 -
Use .justify-content-* classes
Use text-* classes
Now let us understand each method in detail with examples.
The first way to align pagination in Bootstrap 4 is "using the .justify-content-* classes".
Here we will implement this method with a step-by-step example -
Step 1 - Make sure that the Bootstrap 4 JavaScript and CSS files are included in the head of the HTML document.
Step 2 - To build the pagination component, create the
Step 3 - You must add one of the following classes to the
The paging component uses the .justify-content-start style to align left.
The pagination component is centered when using the justify-content-center style.
align-pagination-end: Move the pagination element to the right
Step 4 - This is an example of what the HTML code will look like when pagination is left aligned -
<ul class="pagination justify-content-start"> <li class="page-item"> <a class="page-link" href="#">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="#">Next</a> </li> </ul>
Step 5 - After adding the required classes, the pagination component should align as you expect.
Step 6 - The final code looks like this -
<!DOCTYPE html> <html> <head> <link rel= "stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <div class="row justify-content-center"> <nav aria-label="Page navigation example"> <ul class="pagination justify-content-center"> <li class="page-item"> <a class="page-link" href="#" aria-label="Previous"> <span aria-hidden="true">«</span> <span class="sr-only">Previous</span> </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="#" aria-label="Next"> <span aria-hidden="true">»</span> <span class="sr-only">Next</span> </a> </li> </ul> </nav> </div> </div> </body> </html>
To align the pagination components to the left, center, or right respectively, use . Text Left, Text Center and. Text right class.
We will now look at a step-by-step example of implementing this method -
Step 1 - Create a container div element and assign it the class justify-content-center. As a result, the pagination will be centered within the container.
<div class="justify-content-center">
Step 2 - Create an
<ul class="pagination text-center">
Step 3 - Create
<li class="page-item">
Step 4 - Create an element for the button or page number within each
<a class="page-link" href="#">1</a>
Step 5 - The final code looks like this -
<div class="justify-content-center"> <ul class="pagination text-center"> <li class="page-item"> Previous <li class="page-item"> <a class="page-link" href="#">1</a> <li class="page-item"> 2 <li class="page-item"> 3 <li class="page-item"> Next
Using the built-in classes provided by the framework will make page alignment in Bootstrap 4 easy. By using the above step-by-step process, you can make a fully functional and visually page-centric pagination component. Include the Bootstrap CSS and JavaScript files in the project, create a nav element with the aria-label attribute, and provide an unordered list element containing pagination links. The textcenter class will do this. This strategy makes it easy to change the color and direction of pagination without having to create a lot of unique CSS.
The above is the detailed content of How to align pagination in Bootstrap 4?. For more information, please follow other related articles on the PHP Chinese website!