How to align pagination in Bootstrap 4?
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.
method
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.
Method 1: Use “.justify-content-* classes”
The first way to align pagination in Bootstrap 4 is "using the .justify-content-* classes".
Example
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
- element using the pagination class. For each page, add an element with a page-like link and an
- element with a page-like item inside the
- element.
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
- elements for each page number or previous and next buttons within a
- element. Specify the "page-item" class for each li element.
- element. Assign the class "page-link" to the element.
<li class="page-item">
Copy after loginStep 4 - Create an element for the button or page number within each
<a class="page-link" href="#">1</a>
Copy after loginStep 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
Copy after login
Step 3 - You must add one of the following classes to the
- element to align the pagination component left, center, or 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>
Copy after loginStep 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>
Copy after loginMethod 2: Use text-* class
To align the pagination components to the left, center, or right respectively, use . Text Left, Text Center and. Text right class.
Example
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">
Copy after loginStep 2 - Create an
- element within the container div and give it class pagination and align-pagination-links-to-desired-side (e.g. text-center, text- left, textright) )
<ul class="pagination text-center">
Copy after loginStep 3 - Create
in conclusion
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



This is the 3rd post in a small series we did on form accessibility. If you missed the second post, check out "Managing User Focus with :focus-visible". In

This tutorial demonstrates creating professional-looking JavaScript forms using the Smart Forms framework (note: no longer available). While the framework itself is unavailable, the principles and techniques remain relevant for other form builders.

The CSS box-shadow and outline properties gained theme.json support in WordPress 6.1. Let's look at a few examples of how it works in real themes, and what options we have to apply these styles to WordPress blocks and elements.

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.
