组件如下,
1. 为了提高 selector 优先级,可以链接多个class,例如:
.page-link.page-link-current {
}
2. 取消 button 的默认灰色背景色:
background: none;
3. button 和 a 默认都是 inline
,
4. a 里加 padding,不能保证它们是正方形,但是,通过设置 inline-block,并且设置相同的宽和高,于是就可以。
5. 默认情况下,flex 容器也是一个 block 元素
设置
a {
display: flex;
}
于是,所有的 a 都变成了 block 级元素,于是它们产生换行,从上到下叠加到一起。
6. .pagination
容器并没有设置 width 和 height
代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Accordion Component</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<style>
/*
SPACING SYSTEM (px)
2 / 4 / 8 / 12 / 16 / 24 / 32 / 48 / 64 / 80 / 96 / 128
FONT SIZE SYSTEM (px)
10 / 12 / 14 / 16 / 18 / 20 / 24 / 30 / 36 / 44 / 52 / 62 / 74 / 86 / 98
Main color: #087f5b
Tint1: #099268;
Grey: #343a40
footer-color: #495057;
*/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Inter", sans-serif;
color: #343a40;
line-height: 1;
display: flex;
justify-content: center;
}
.pagination {
display: flex;
align-items: center;
gap: 12px;
background-color: #e6fcf5;
margin-top: 200px;
}
.btn {
border: 1px solid #087f5b;
width: 48px;
height: 48px;
border-radius: 50%;
background: none;
}
.btn:hover {
background-color: #087f5b;
cursor: pointer;
}
.btn:hover .btn-icon {
stroke: #fff;
}
.btn-icon {
height: 24px;
width: 24px;
stroke: #087f5b;
}
.page-link:link,
.page-link:visited {
font-size: 18px;
color: #343a40;
text-decoration: none;
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.page-link:hover,
.page-link:active,
/* specificity of .page-link--current ALONE is
lower then the above .page-link:link,
so color: #fff; will not apply, to solve
this problem, two classes chained and both
are selected: .page-link.page-link--current
*/
.page-link.page-link--current {
background-color: #087f5b;
color: #fff;
}
.dots {
color: #868e96;
}
</style>
</head>
<body>
<div class="pagination">
<button class="btn">
<svg
xmlns="http://www.w3.org/2000/svg"
class="btn-icon"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M15 19l-7-7 7-7"
/>
</svg>
</button>
<a href="#" class="page-link">1</a>
<a href="#" class="page-link">2</a>
<a href="#" class="page-link page-link--current">3</a>
<a href="#" class="page-link">4</a>
<a href="#" class="page-link">5</a>
<a href="#" class="page-link">6</a>
<span class="dots">...</span>
<a href="#" class="page-link">23</a>
<button class="btn">
<svg
xmlns="http://www.w3.org/2000/svg"
class="btn-icon"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 5l7 7-7 7"
/>
</svg>
</button>
</div>
</body>
</html>