首页 > 其他分享 >如何使用HTML和CSS进行分页?

如何使用HTML和CSS进行分页?

时间:2022-11-08 12:32:21浏览次数:42  
标签:pagination hover 分页 color section HTML CSS

如何使用HTML和CSS进行分页?_分页

英文 | https://www.geeksforgeeks.org/how-to-make-a-pagination-using-html-and-css/?ref=rp

翻译 | web前端开发(web_qdkf)


要为页面创建分页效果非常简单,你可以使用Bootstrap,JavaScript以及最简单的HTML和CSS方法来实现。

当网站在单个页面上包含很多内容时,分页会很有用,因为单个页面将所有这些主题放在一起看起来都不太好。

很少有网站会使用滚动条来避免分页,反之亦然。但是,最好的外观呈现时滚动和分页相结合。

作为开发人员,你可以在页面上放置一些内容,以使该页面有些可滚动,直到烦人为止。

你可以使用分页将保留那些先前的内容并继续到新的内容页面,并且主题将相同。

在本文中,我们先创建分页的基本结构。在这里,我们还将附加title属性,以便用户可以知道分页的下一页上的内容类型。

HTML代码结构如下:

<!DOCTYPE html> 
<html>


<head>
<title>
How to make a Pagination
using HTML and CSS ?
</title>
</head>


<body>
<center>


<!-- Header and Slogan -->
<h1>GeeksforGeeks</h1>
<p>A Computer Science Portal for Geeks</p>
</center>


<!-- contern in this Section -->
<div class="content">
<h3>Interview Experiences:</h3>


<article>
Share Your Questions/Experience or share
your "Interview Experience", please mail
your interview experience to
[email protected]. Also, to
share interview questions, please add
questions at Contribute a Question! You
can also find company specific Interview
Questions at our PRACTICE portal !
</article>
</div>


<!-- pagination elements -->
<div class="pagination_section">
<a href="#"><< Previous</a>
<a href="#" title="Algorithm">1</a>
<a href="#" title="DataStructure">2</a>
<a href="#" title="Languages">3</a>
<a href="#" title="Interview" class="active">4</a>
<a href="#" title="practice">5</a>
<a href="#">Next >></a>
</div>
</body>


</html>

然后,我们再通过CSS创建网站的外观效果。

CSS代码结构如下:

<style> 


/* header styling */
h1 {
color: green;
}


/* pagination position styling */
.pagination_section {
position: absolute;
top: 500px;
right: 230px;
}


/* pagination styling */
.pagination_section a {
color: black;
padding: 10px 18px;
text-decoration: none;
}


/* pagination hover effect on non-active */
.pagination_section a:hover:not(.active) {
background-color: #031F3B;
color: white;
}


/* pagination hover effect on active*/
a:nth-child(5) {
background-color: green;
color: white;
}


a:nth-child(1) {
font-weight: bold;
}


a:nth-child(7) {
font-weight: bold;
}


.content {
margin: 50px;
padding: 15px;
width: 800px;
height: 200px;
border: 2px solid black;
}
</style>

最后,将HTML和CSS代码进行组合。

我们就得到了最终代码结构如下:

<!DOCTYPE html> 
<html>


<head>
<title>
How to make a Pagination
using HTML and CSS ?
</title>


<style>


/* header styling */
h1 {
color: green;
}
/* pagination position styling */


.pagination_section {
position: absolute;
top: 500px;
right: 230px;
}
/* pagination styling */


.pagination_section a {
color: black;
padding: 10px 18px;
text-decoration: none;
}
/* pagination hover effect on non-active */


.pagination_section a:hover:not(.active) {
background-color: #031F3B;
color: white;
}
/* pagination hover effect on active*/


a:nth-child(5) {
background-color: green;
color: white;
}


a:nth-child(1) {
font-weight: bold;
}


a:nth-child(7) {
font-weight: bold;
}


.content {
margin: 50px;
padding: 15px;
width: 700px;
height: 200px;
border: 2px solid black;
}
</style>
</head>


<body>
<center>


<!-- Header and Slogan -->
<h1>GeeksforGeeks</h1>
<p>A Computer Science Portal for Geeks</p>
</center>


<!-- contern in this Section -->
<div class="content">
<h3>Interview Experiences:</h3>


<article>
Share Your Questions/Experience or share
your "Interview Experience", please mail
your interview experience to
[email protected]. Also, to
share interview questions, please add
questions at Contribute a Question! You
can also find company specific Interview
Questions at our PRACTICE portal !
</article>
</div>


<!-- pagination elements -->
<div class="pagination_section">
<a href="#"><< Previous</a>
<a href="#" title="Algorithm">1</a>
<a href="#" title="DataStructure">2</a>
<a href="#" title="Languages">3</a>
<a href="#" title="Interview" class="active">4</a>
<a href="#" title="practice">5</a>
<a href="#">Next >></a>
</div>
</body>


</html>

最终效果如下:

如何使用HTML和CSS进行分页?_css_02


本文完~


如何使用HTML和CSS进行分页?_html_03

如何使用HTML和CSS进行分页?_html_04

标签:pagination,hover,分页,color,section,HTML,CSS
From: https://blog.51cto.com/u_15809510/5832564

相关文章

  • HTML5 WEB怎么实现大文件上传
    ​ 需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500G内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以500G来进行限制。PC端全平......
  • 关于 Angular 部署以及 index.html 里 base hRef 属性的关联关系
    直接在SAP电商云SpartacusUI项目下,运行命令行ngbuild,输出如下:dist文件夹:把dist文件夹下的mystore直接放到tomcatwebapps文件夹下面,运行时:如果修改b......
  • HTML-head元素
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><!--下面这些标签可用在head部分:<base>,<link>,<meta>,<script>,<style>,......
  • CSS布局秘籍(2)-6脉神剑
    HTML系列:人人都懂的HTML基础知识-HTML教程(1)HTML元素大全(1)HTML元素大全(2)-表单CSS系列:CSS基础知识筑基常用CSS样式属性CSS选择器大全48式CSS布局秘籍(1)......
  • CSS3的 transform属性,怎么才能让他同时执行多个不同动画(变换属性)效果
    如果要给一个dom元素,同时设置多个不同的CSS变换(transform)属性时,在属性中间用空格隔开即可,旋转缩放扭曲等同时执行多个效果!div{width:100px;height:1......
  • CSS鼠标样式【cursor】
    cursor:hand;手型cursor:pointer;手型cursor:auto;由系统自动给出cursor:crosshair;十字型cursor:text;I字形cursor:wait;等待cursor:default;默认cursor:e-resize;......
  • 通过css 改变通过img标签引入的svg颜色
    前言修改svg颜色,一般直接修改文件的svg的fill属性就可以了,可以直接改svg属性,也可以通过css修改,但是前端一般都是通过img标签直接引入的svg图片,这样不管是从后期维护还是代......
  • webpack中配置CSS兼容性时报错 Failed to parse package.json data
      是因为在package.json中添加了注释正确webpack配置CSS兼容性的步骤:npmipostcss-loaderpostcss-preset-env-D/webpack.config.jsmodule:{    ru......
  • CSS书写顺序及其原因
    记得刚开始学习前端的时候,每次写css样式都是用到什么就在样式表后添加什么,完全没有考虑到样式属性的书写顺序对网页加载代码的影响。后来逐渐才知道正确的样式顺序不仅易于......
  • windbg下看系统非分页内存
       这篇文章实在是闲的无聊才写的,因为快过年了...文章基于xpsp3   先看看和非分页内存相关的全局变量,也好有个大局观:kd>xnt!MmNonPaged*805517d8nt!Mm......