Home > Article > Web Front-end > A brief discussion on how to use the Pagination component of Bootstrap5
This article will introduce to you the usage of the Pagination component in Bootstrap5. I hope it will be helpful to everyone!
[Related recommendation: "bootstrap tutorial"]
Page navigation is generally used for article list pages, download lists, picture lists, etc. Because there is a lot of data, it is impossible to display it on one page. Generally, page navigation includes previous page, next page, digital page number, etc. The following is a simple example:
<nav aria-label="Page navigation"> <ul class="pagination"> <li class="page-item"><a class="page-link" href="#">上一页</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="#">下一页</a></li> </ul> </nav>
Use icons or symbols to replace certain paging links. Text.
<nav aria-label="Page navigation example"> <ul class="pagination"> <li class="page-item"> <a class="page-link" href="#" aria-label="Previous"> <span aria-hidden="true">«</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> </a> </li> </ul> </nav>
Paging links can be customized according to different situations. Use disabled for links that appear to be unclickable, and active for links that appear to be on the current page.
Although the .disabled class uses pointer-events: none to attempt to disable a's link functionality, the CSS properties have not been standardized and keyboard navigation is not considered. Therefore, you should always add tabindex="-1" on disabled links and use custom JavaScript to completely disable their functionality.
<nav aria-label="..."> <ul class="pagination"> <li class="page-item disabled"> <a class="page-link" href="#" tabindex="-1" aria-disabled="true">Previous</a> </li> <li class="page-item"><a class="page-link" href="#">1</a></li> <li class="page-item active" aria-current="page"> <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="#">Next</a> </li> </ul> </nav>
Like larger or smaller pagination? Add pagination-lg or pagination-sm, or use another size.
<nav aria-label="..."> <ul class="pagination pagination-lg"> <li class="page-item active" aria-current="page"> <span class="page-link">1</span> </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> <nav aria-label="..."> <ul class="pagination"> <li class="page-item active" aria-current="page"> <span class="page-link">1</span> </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> <nav aria-label="..."> <ul class="pagination pagination-sm"> <li class="page-item active" aria-current="page"> <span class="page-link">1</span> </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>
The default paging navigation is left aligned. Foreigners are more accustomed to left alignment. We Chinese like to be centered. You can use the flexible box general class Change the alignment of the pagination component. Just add justify-content-center to the ul class. Of course, you can also use justify-content-end to align to the right, although this is rare.
<nav aria-label="Page navigation example"> <ul class="pagination justify-content-center"> <li class="page-item disabled"> <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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="#">Next</a> </li> </ul> </nav> <nav aria-label="Page navigation example"> <ul class="pagination justify-content-end"> <li class="page-item disabled"> <a class="page-link" href="#" tabindex="-1" aria-disabled="true">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="#">Next</a> </li> </ul> </nav>
If this article is helpful to you, please remember to like it!
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of A brief discussion on how to use the Pagination component of Bootstrap5. For more information, please follow other related articles on the PHP Chinese website!