組件分頁_如何創建分頁組件

組件分頁

The theme for week #17 of the Weekly Coding Challenge is:

每周編碼挑戰第17周的主題是:

分頁 (Pagination)

A Pagination Component is used on websites where you have more content available than you want to display at one time to the user so you'd split it on multiple pages. By separating the content on different pages you are also saving a lot of bandwidth for the user because it won't be required to download all the information at once.

分頁組件用于網站上,您所擁有的內容比一次要向用戶顯示的內容要多,因此您可以將其拆分為多個頁面。 通過分隔不同頁面上的內容,您還為用戶節省了大量帶寬,因為不需要一次下載所有信息。

Some examples where you'd have a pagination: a blog with multiple pages, an online store with multiple products, etc.

您可以進行分頁的一些示例 :具有多個頁面的博客,具有多種產品的在線商店等。

In this article we're going to build this Pagination Component:

在本文中,我們將構建此分頁組件 :

Note: the pagination is not functional, it's just for demo purposes (the visual). As an extra challenge, you can link this on a real website.

注意 :分頁功能不起作用,僅用于演示目的(視覺效果)。 作為額外的挑戰,您可以在一個真實的網站上鏈接它。

HTML (The HTML)

For the HTML structure we're going to use an ul as a wrapper with multiple lis. Each li will have an a tag within it because it's clickable (and semantic) and it'll send the user to the required page (if needed).

對于HTML結構,我們將使用ul作為帶有多個li的包裝器。 每個li都將在其中包含a標簽,因為它是可單擊的(和語義),并且會將用戶定向到所需的頁面(如果需要)。

We're also using FontAwesome for the icons (left, right and the dots icons).

我們還將FontAwesome用于圖標(左側,右側和圓點圖標)。

<ul class="pagination"><li><a href="#"><i class="fas fa-chevron-left"></i></a></li><li><a href="#"><i class="fas fa-ellipsis-h"></i></a></li><li><a href="#">2</a></li><li class="active"><a href="#">3</a></li><li><a href="#">4</a></li><li><a href="#">5</a></li><li><a href="#"><i class="fas fa-ellipsis-h"></i></a></li><li><a href="#"><i class="fas fa-chevron-right"></i></a></li>
</ul>

As you can see I also added an .active class to one of the lis - this is just to highlight the page we are on.

正如你可以看到我還增加了.active類的一個li秒-這僅僅是重點突出一頁,我們都在。

CSS (The CSS)

I'm going to paste the CSS and we'll discuss the important pieces afterwards.

我將粘貼CSS,然后我們將討論重要的部分。

.pagination {border: 2px solid #aaa;border-radius: 4px;display: flex;list-style-type: none;overflow: hidden;padding: 0;
}.pagination li {background-color: #fff;
}.pagination li:hover,
.pagination li.active {background-color: #aaa;
}.pagination li a {color: #555;display: block;font-weight: bold;padding: 10px 15px;text-decoration: none;
}.pagination li:hover a,
.pagination li.active a {color: #fff;
}

Things to note:

注意事項:

  1. The ul / .pagination it's a flex container - this is because it's much easier to position the lis within it by using flexbox (and who doesn't like flexbox? ?)

    ul / .pagination是一個flex容器-這是因為使用flexbox將li放置在其中很容易(而且誰不喜歡flexbox ??)

  2. Because we have a little bit of a border-radius on the ul we need to add overflow: hidden because otherwise the li's corner will be visible on top of the border of the ul (remove the overflow and you'll see what I mean)

    因為我們在ul上有一個小border-radius ,所以我們需要添加overflow: hidden因為否則, li的角將在ul的邊界上可見(去除溢出,您將看到我意思)

  3. We have the same styling on li:hover as on li.active, but you can differentiate between these to states if you want

    我們在li:hover上的樣式與在li.active上的樣式相同,但是您可以根據需要在狀態之間進行區分

Other than that, I believe it's pretty straightforward, but if you have any questions please let me know. ?

除此之外,我相信這非常簡單,但是如果您有任何疑問,請告訴我。 ?

結論 (Conclusion)

There are other variants of paginations out there on the web. Find one you like and convert it to code.

網絡上還有其他分頁方式。 找到您喜歡的一個并將其轉換為代碼。

Make sure you share with me what you've built!

確保您與我分享您的作品!

Happy Coding! ?

編碼愉快! ?

翻譯自: https://www.freecodecamp.org/news/how-to-create-a-pagination-component/

組件分頁

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391204.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391204.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391204.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

web-項目管理

總結 目的是 1.可查詢 2.方便團隊管理 每個成員都可以看到任何東西 項目 需求 計劃 bug 按模板來 1.問題描述 2.原因分析 3.解決方法 開發 提交代碼 按模板來 1.問題描述 2.原因分析 3.解決方法 打包 更新說明文件.txt 按模板來 一、更新說明 1.問題描述 1&#xff09;計劃號 2…

cnn對網絡數據預處理_CNN中的數據預處理和網絡構建

cnn對網絡數據預處理In this article, we will go through the end-to-end pipeline of training convolution neural networks, i.e. organizing the data into directories, preprocessing, data augmentation, model building, etc.在本文中&#xff0c;我們將遍歷訓練卷積神…

leetcode 554. 磚墻

你的面前有一堵矩形的、由 n 行磚塊組成的磚墻。這些磚塊高度相同&#xff08;也就是一個單位高&#xff09;但是寬度不同。每一行磚塊的寬度之和應該相等。 你現在要畫一條 自頂向下 的、穿過 最少 磚塊的垂線。如果你畫的線只是從磚塊的邊緣經過&#xff0c;就不算穿過這塊磚…

django-rest-framework解析請求參數過程詳解

https://www.jb51.net/article/165699.htm 轉載于:https://www.cnblogs.com/gcgc/p/11544187.html

遞歸 和 迭代 斐波那契數列

#include "stdio.h"int Fbi(int i) /* 斐波那契的遞歸函數 */ { if( i < 2 ) return i 0 ? 0 : 1; return Fbi(i - 1) Fbi(i - 2); /* 這里Fbi就是函數自己&#xff0c;等于在調用自己 */ }int main() { int i; int a[40]; printf("迭代顯示斐波那契數列…

單元測試 python_Python單元測試簡介

單元測試 pythonYou just finished writing a piece of code and you are wondering what to do. Will you submit a pull request and have your teammates review the code? Or will you manually test the code? 您剛剛編寫了一段代碼&#xff0c;并且想知道該怎么做。 您…

飛行模式的開啟和關閉

2019獨角獸企業重金招聘Python工程師標準>>> if(Settings.System.getString(getActivity().getContentResolver(),Settings.Global.AIRPLANE_MODE_ON).equals("0")) { Settings.System.putInt(getActivity().getContentResolver(),Settings.Global.AIRPLA…

消解原理推理_什么是推理統計中的Z檢驗及其工作原理?

消解原理推理I Feel:我覺得&#xff1a; The more you analyze the data the more enlightened, data engineer you will become.您對數據的分析越多&#xff0c;您將變得越發開明。 In data engineering, you will always find an instance where you need to establish whet…

pytest+allure測試框架搭建

https://blog.csdn.net/wust_lh/article/details/86685912 https://www.jianshu.com/p/9673b2aeb0d3 定制化展示數據 https://blog.csdn.net/qw943571775/article/details/99634577 環境說明&#xff1a; jdk 1.8 python 3.5.3 allure-commandline 2.13.0 文檔及下載地址&…

lintcode433 島嶼的個數

島嶼的個數 給一個01矩陣&#xff0c;求不同的島嶼的個數。 0代表海&#xff0c;1代表島&#xff0c;如果兩個1相鄰&#xff0c;那么這兩個1屬于同一個島。我們只考慮上下左右為相鄰。 您在真實的面試中是否遇到過這個題&#xff1f; Yes樣例 在矩陣&#xff1a; [[1, 1, 0, …

大數據分析要學習什么_為什么要學習數據分析

大數據分析要學習什么The opportunity to leverage insights from data has never been greater.利用來自數據的洞察力的機會從未如此大。 Humans tend to generate a lot of data each day - from heart rates to favorite songs, fitness goals and movie preferences. You …

POJ - 3257 Cow Roller Coaster (背包)

題目大意&#xff1a;要用N種材料建一條長為L的路&#xff0c;如今給出每種材料的長度w。起始地點x。發費c和耐久度f 問&#xff1a;在預算為B的情況下&#xff0c;建好這條路的最大耐久度是多少 解題思路&#xff1a;背包問題 dp[i][j]表示起始地點為i。發費為j的最大耐久度…

leetcode 1473. 粉刷房子 III(dp)

在一個小城市里&#xff0c;有 m 個房子排成一排&#xff0c;你需要給每個房子涂上 n 種顏色之一&#xff08;顏色編號為 1 到 n &#xff09;。有的房子去年夏天已經涂過顏色了&#xff0c;所以這些房子不需要被重新涂色。 我們將連續相同顏色盡可能多的房子稱為一個街區。&a…

大學生信息安全_給大學生的信息

大學生信息安全You’re an undergraduate. Either you’re graduating soon (like me) or you’re in the process of getting your first college degree. The process is not easy and I can only assume how difficult the pressures on Masters and Ph.D. students are. Ho…

打破冷漠僵局文章_保持冷靜并打破僵局-最佳

打破冷漠僵局文章Hack The Box (HTB) is an online platform allowing you to test your penetration testing skills. It contains several challenges that are constantly updated. Some of them simulating real world scenarios and some of them leaning more towards a …

使用DOM Breakpoints找到修改屬性的Javascript代碼

使用Chrome開發者工具的DOM斷點功能可以讓您快速找到修改了某一個DOM元素的Javascript代碼。 在Chrome開發者工具里&#xff0c;選中想要監控的DOM元素&#xff0c;點擊右鍵&#xff0c;選擇Break on->Attributes modifications: 之后在DOM Breakpoints的tab里能看到對應的斷…

特斯拉最安全的車_特斯拉現在是最受歡迎的租車選擇

特斯拉最安全的車Have you been curious to know which cars are most popular in US and what are their typical rental fares in various cities? As the head of Product and Data Science at an emerging technology start-up, Ving Rides, these were some of the quest…

leetcode 740. 刪除并獲得點數(dp)

給你一個整數數組 nums &#xff0c;你可以對它進行一些操作。 每次操作中&#xff0c;選擇任意一個 nums[i] &#xff0c;刪除它并獲得 nums[i] 的點數。之后&#xff0c;你必須刪除每個等于 nums[i] - 1 或 nums[i] 1 的元素。 開始你擁有 0 個點數。返回你能通過這些操作…

WebSocket入門

WebSocket前言  WebSocket是HTML5的重要特性&#xff0c;它實現了基于瀏覽器的遠程socket&#xff0c;它使瀏覽器和服務器可以進行全雙工通信&#xff0c;許多瀏覽器&#xff08;Firefox、Google Chrome和Safari&#xff09;都已對此做了支持。 在WebSocket出現之前&#xff…

安卓游戲開發推箱子_保持冷靜并砍箱子-開發

安卓游戲開發推箱子Hack The Box (HTB) is an online platform allowing you to test your penetration testing skills. It contains several challenges that are constantly updated. Some of them simulating real world scenarios and some of them leaning more towards …