马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
在网页开辟中,一个好的加载页面不但能提拔用户体验,还能为网站增长独特的风格。下面将对一段实现加载页面效果的 HTML 与 CSS 代码举行详细先容。
团体结构概述
该代码创建了一个包罗背景、内容容器以及加载动画元素的网页页面。团体结构通过多个div元素和 CSS 样式来实现,告急包括背景层、内容层以及加载动画层。
HTML 部门
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- /* 样式代码部分,后续会详细介绍 */
- </style>
- </head>
- <body>
- <div class="xiao">
- <div class="xiao1">
- <div class="xiao2"></div>
- </div>
- </div>
- <div class="xiao3"></div>
- </body>
- </html>
复制代码
- <!DOCTYPE html>:声明文档范例为 HTML5。
- <html lang="en">:界说 HTML 文档的根元素,并指定语言为英语。
- <head> 部门:包罗了文档的元数据,如字符编码、视口设置以及页面标题。
- <meta charset="UTF-8">:设置字符编码为 UTF-8,确保页面可以或许准确体现各种字符。
- <meta name="viewport" content="width=device-width, initial-scale=1.0">:设置视口,使页面在差别装备上可以或许准确缩放和体现。
- <title>Document</title>:界说页面的标题,这里体现为 “Document”。
- <body> 部门:包罗了页面的实际内容。
- <div class="xiao">:这是页面的最外层容器,用于设置背景图像和团体结构。
- <div class="xiao1">:嵌套在.xiao容器内,用于放置告急内容区域,设置了白色背景。
- <div class="xiao2">:嵌套在.xiao1内,是一个体现特定图像的容器。
- <div class="xiao3">:独立于.xiao容器,用于体现加载动画的图像。
CSS 部门
- /* 去除默认的外边距和内边距 */
- body,
- html {
- margin: 0;
- padding: 0;
- height: 100%;
- }
- div.xiao {
- position: relative;
- z-index: 1;
- /* 设置宽度和高度为100% */
- width: 100%;
- height: 100%;
- background-image: url(./png/bg.webp);
- /* 使背景图像覆盖整个元素 */
- background-size: cover;
- /* 使背景图像居中 */
- background-position: center;
- }
- .xiao1 {
- position: fixed;
- z-index: 2;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- width: 90%;
- height: 84%;
- background-color: #fffcf2;
- background-position: center;
- }
- .xiao2 {
- position: fixed;
- top: 3%;
- left: 50%;
- transform: translate(-50%, 0);
- width: 400px;
- height: 280px;
- background-image: url(./png/logo_portal.svg);
- z-index: 3;
- background-size: cover;
- background-position: center;
- }
- .xiao3 {
- position: fixed;
- top: 53%;
- left: 50%;
- transform: translate(-50%, 0);
- width: 190px;
- height: 190px;
- background-image: url(./png/loading.svg);
- z-index: 3;
- background-size: cover;
- background-position: center;
- /* 修改旋转速度为1秒一圈 */
- animation: spin 5s linear infinite;
- }
- @keyframes spin {
- 0% {
- transform: translate(-50%, 0) rotate(0deg);
- }
- 100% {
- transform: translate(-50%, 0) rotate(360deg);
- }
- }
复制代码
- 完备代码展示
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- /* 去除默认的外边距和内边距 */
- body,
- html {
- margin: 0;
- padding: 0;
- height: 100%;
- }
- div.xiao {
- position: relative;
- z-index: 1;
- /* 设置宽度和高度为100% */
- width: 100%;
- height: 100%;
- background-image: url(./png/bg.webp);
- /* 使背景图像覆盖整个元素 */
- background-size: cover;
- /* 使背景图像居中 */
- background-position: center;
- }
- .xiao1 {
- position: fixed;
- z-index: 2;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- width: 90%;
- height: 84%;
- background-color: #fffcf2;
- background-position: center;
- }
- .xiao2 {
- position: fixed;
- top: 3%;
- left: 50%;
- transform: translate(-50%, 0);
- width: 400px;
- height: 280px;
- background-image: url(./png/logo_portal.svg);
- z-index: 3;
- background-size: cover;
- background-position: center;
- }
- .xiao3 {
- position: fixed;
- top: 53%;
- left: 50%;
- transform: translate(-50%, 0);
- width: 190px;
- height: 190px;
- background-image: url(./png/loading.svg);
- z-index: 3;
- background-size: cover;
- background-position: center;
- /* 修改旋转速度为1秒一圈 */
- animation: spin 5s linear infinite;
- }
- @keyframes spin {
- 0% {
- transform: translate(-50%, 0) rotate(0deg);
- }
- 100% {
- transform: translate(-50%, 0) rotate(360deg);
- }
- }
- </style>
- </head>
- <body>
- <div class="xiao">
- <div class="xiao1">
- <div class="xiao2"></div>
- </div>
- </div>
- <div class="xiao3"></div>
- </body>
- </html>
复制代码 效果如图
-
|