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

article/2025/8/15 16:34:11

英文 | 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  contribute@geeksforgeeks.org. 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_p"> <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_p { position: absolute; top: 500px; right: 230px; } /* pagination styling */ .pagination_p a { color: black; padding: 10px 18px; text-decoration: none; } /* pagination hover effect on non-active */ .pagination_p 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_p { position: absolute; top: 500px; right: 230px; } /* pagination styling */ .pagination_p a { color: black; padding: 10px 18px; text-decoration: none; } /* pagination hover effect on non-active */ .pagination_p 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  contribute@geeksforgeeks.org. 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_p"> <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> 

最终效果如下:

本文完~


http://chatgpt.dhexx.cn/article/WyQBOj0Z.shtml

相关文章

html分页过多,实现分页处理,固定分页数目,数目始终中间显示,自定义分页跳转(在结尾的代码)

目录 问题描述&#xff1a; 效果展示&#xff1a; 解决思想&#xff1a; 一、首先你想要先判断当前数据库表中的页数和3是什么关系 二、其次讨论一下特殊的首页和尾页&#xff0c;也就是第1页和第8页 三、如何对userPageInfo.pageNum-1和userPageInfo.pageNum1进行判断 …

【全栈之前端编程】Javaweb使用thymeleaf局部刷新结合Layui插件实现Html分页

热门系列&#xff1a; 程序人生&#xff0c;精彩抢先看 目录 1、前言 2、正文 2.1 开发环境介绍 2.2 实现代码 2.3 实现流程说明 2.4 实现效果 程序人生&#xff0c;精彩抢先看 1、前言 最近个人在做开发的时候&#xff0c;需要实现前端的Html页面分页。由于好一段时间…

HTML分页插件功能实现

分页功能实现案例展示如下&#xff1a; 1.先引入css样式和jQuery&#xff0c;再引入分页插件toPage.js&#xff0c;谨记顺序不能乱 <link rel"stylesheet" href"css/toPage.css"> <script src"script/jquery.min.js"></script&…

java html页面设计_Java实战之html分页设计

分页设计 原则 由于每次要将对应页数所需要的数据在jsp或者html等文件中显示出来&#xff0c;所以要将这些数据封装在一个javabean中 &#xff0c;后台都将查询到的数据导入到对应的javabean对象实例中&#xff0c;我们再将该对象存入request作用域&#xff0c;html或者jsp页面…

html分页效果怎么加,CSS 分页效果制作实例教程

这个教程也包含有实现Flickr、Digg式的简洁分页样式的HTML/CSS代码&#xff0c;随时可以应用于你的WEB项目中。 Update as March 17, 2008:My friends Simone Saveri solved some issuse with IE6 and IE7. Download this tutorial (original) Download this tutorial (Simone …

分页阅读html,html分页

1 (function($, window, document, undefined) { 2 //定义分页类 3 function Paging(element, options) { 4 this.element element; 5 //传入形参 6 this.options { 7 pageNo: options.pageNo||1, 8 totalPage: options.totalPage, 9 totalSize:options.totalSize, 10 callba…

JS实现前端分页

一、HTML部分 <!doctype html> <html> <head><meta charsetutf-8><script src"js/jquery.js"></script><style type"text/css">a{text-decoration: none;}table {border-collapse:collapse;width: 100%;font-s…

html中的分页条怎么写,html如何制作分页

一般的制作页面都会使用到分页&#xff0c;那么你知道分页功能是怎么实现的吗&#xff1f;让我们一起来学习一下html如何制作分页吧。 新建html页面。如图&#xff1a; 在html页面找到body标签&#xff0c;在body标签里新建一个div标签&#xff0c;然后在div标签中新建a标签&am…

html分页功能

&#xff08;代码来源 http://www.xwcms.net/&#xff0c;非原创&#xff01;&#xff09; 1、导入css、js文件 2、根据index.html中的页面进行相应的修改 主要函数实现&#xff08;其中&#xff0c;#exampletable为需要分页的table的id&#xff09; <script type"te…

HTML+CSS实现网页分页页码

直角分页页码实现 <!doctype html> <html> <head> <meta charset"utf-8"> <title>直角分页页码</title> <style type"text/css">/*设置 a 标签的css样式*/.page-normal a{border: 1px solid #ff6500;padding: …

前端 利用html实现分页切换效果

本篇文章主要要实现的功能效果如下&#xff1a; 包含首页 尾页 上一页 下一页 总计的页数以及总计的条数还有跳转的功能 整体思想&#xff1a;先定位一个中心页 上一页、下一页就是根据定位中心页然后加减就可以实现 首页就是要根据一次要展示几页&#xff0c;然后分别展示…

HTML实现分页功能

思路 主要是通过display: block和display: none来实现页面的切换。 将每个页面用一个div包起来&#xff0c;默认第一个页面的样式是display: block&#xff0c;其他页面的样式是display: none&#xff0c;然后通过JavaScript获取鼠标点击事件来隐藏其他页面&#xff0c;显示当…

html+js实现分页功能

1、分页功能实现效果如下&#xff1a; 2、代码如下 <!DOCTYPE html > <html> <head><title> 消息呈现 </title><link rel"icon" href"picture.ico" type"image/x-icon" /><script src"../js/jquer…

阿里云服务器Windows系统搭建Java Web网站教程

一、首先首先搜索阿里云官网&#xff0c;购买服务器 二、 打开控制台-云服务器ECS-实例&#xff0c;先停止运行&#xff0c;再选择更换系统盘&#xff0c;选择带有jdk和tomcat和MySQL的系统镜像安装。 三、 待服务器重启后&#xff0c;打开Windows自带的远程连接软件&#xff0…

关于阿里云Centos服务器搭建Java网站不能访问的问题

转载请注明出处&#xff1a;http://blog.csdn.net/l1028386804/article/details/73864773 首先阿里云提供的手册是没问题的 手工搭建 然后我在地址栏输入服务器地址之后总是提示无法访问&#xff01; 输入命令 netstat -tunlp&#xff0c;80端口确实是在监听&#xff08;这…

【阿里云】基于ECS搭建Java Web开发环境

点击右侧 切换至Web Terminal&#xff0c;执行以下命令&#xff0c;查看yum源中JDK版本。 yum list java* 执行以下命令&#xff0c;使用yum安装JDK1.8。 yum -y install java-1.8.0-openjdk* 执行以下命令&#xff0c;查看是否安装成功。 java -version 如果显示如下图内…

一、申请阿里云服务器及搭建Java开发环境教程 -- 购买阿里云服务器(1)

注&#xff1a;云服务器开发环境如下 &#xff08;CentOS JDK1.7 Mysql ZooKeeper Redis Nginx maven中央库Nexus&#xff09; 一、购买阿里云服务器 1、百度搜索阿里云官网或地址栏输入 https://www.aliyun.com 进入阿里云官网&#xff0c;登录或注册进入&#xff0c;…

阿里云搭建网站

首次搭建个人小站&#xff0c;建议购买域名和服务器到知名商家&#xff0c;比如阿里云&#xff0c;百度云等。因为阿里云绑定了个人淘宝账号&#xff0c;所以成为本人首选&#xff0c;嘿嘿。 购买域名。点击打开http://www.aliyun.com/ 链接地址。并点击右上角的“万网”标记。…

阿里云服务器部署javaweb

1.首先购买服务器和域名 服务器类型选择&#xff1a;云服务器ecs&#xff08;不要选择突发性能型&#xff09;&#xff0c;域名自便&#xff08;注&#xff1a;域名解析需要备案&#xff0c;此类型服务器要求有效期大于三个月才可以备案&#xff09;。 服务器设置&#xff1a…

教你从0开始部署阿里云服务器,阿里云服务器搭建网站教程

教你从0开始部署阿里云服务器&#xff0c;阿里云服务器部署网站的办法&#xff0c;阿里云搭建项目的办法&#xff0c;阿里云服务器搭建网站教程 1.购买 登录官网点击下面链接&#xff1a;阿里云注册链接 查看云服务器购买列表&#xff0c;购买时选择地区、操作系统镜像等&…