使用html+css+js实现完整的登录注册页面

news2024/9/22 15:27:58

在这篇博客中,我们将讨论如何使用简单的 HTML 和 CSS 构建一个登录与注册页面。这个页面包含两个主要部分:登录界面和注册界面。我们还会展示如何通过 JavaScript 切换这两个部分的显示状态。

页面结构

我们将创建一个页面,其中包含两个主要的 div 元素:一个用于登录,另一个用于注册。默认情况下,登录部分会显示,注册部分会隐藏。用户可以通过点击按钮在这两个部分之间切换。

HTML 代码

以下是页面的 HTML 结构:

<div class="box">
        <div style=" width: 100%;height: 100%;">
            <div style="display: block;" id="myLogin" style="width: 100%;height: 100%;">
                <div class="left">
                    <button class="register" type="submit" onclick="toggleDivRegister()">去注册</button>
                </div>
                <div class="right" style="margin-left: 300px;">
                    <h2>登 录</h2>
                    <form action="">
                        <div style="width: 400px;">
                            <div>
                                <div style="display: flex;">
                                    <i class="iconPhone distant1"></i>
                                    <input class="content" type="phone" placeholder="手机号" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant1"></i>
                                    <input class="content" type="password" placeholder="密码" required>
                                </div>
                            </div>

                            <div style="padding: 10px;">
                                <span style="float: left;display: flex;justify-content: center;align-content: center;">
                                    <input type="checkbox" style="vertical-align:top;" /><span
                                        style="font-size: 14px;vertical-align:top;padding-left: 5px;">记住密码</span>
                                </span>
                                <span style="float: right;font-size: 15px;color: rgb(74, 159, 244);">忘记密码?</span>
                            </div>
                        </div>

                        <button class="submit" type="submit">登录</button>
                    </form>
                </div>
            </div>
            <div style="display: none;" id="myRegister" style="width: 100%;height: 100%;">
                <div class="left">
                    <button class="register" type="submit" onclick="toggleDivLogin()">去登录</button>
                </div>
                <div class="right" style="margin-left: 300px;">
                    <h2 style="color: #74b9ff;font-size: 50px;margin-top: 40px;">注 册</h2>
                    <form action="">
                        <div style="width: 400px;">
                            <div>
                                <div style="display: flex;">
                                    <i class="iconPhone distant2"></i>
                                    <input class="content" type="phone" placeholder="请输入手机号"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconUser distant2"></i>
                                    <input class="content" type="username" placeholder="请输入用户名"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant2"></i>
                                    <input class="content" type="password" placeholder="请输入密码"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant2"></i>
                                    <input class="content" type="password_reset" placeholder="请再次输入密码"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                            </div>
                        </div>

                        <button class="submit" type="submit" onclick="submitRegister()">立即注册</button>
                    </form>
                </div>
            </div>
        </div>
    </div>

JavaScript 代码

为了实现登录和注册界面的切换,我们需要一些 JavaScript 代码。以下是实现这些功能的 JavaScript 函数:

function toggleDivRegister() {
            var x = document.getElementById("myRegister");
            var y = document.getElementById("myLogin");
            x.style.display = "block";
            y.style.display = "none";
        }
        function toggleDivLogin() {
            var x = document.getElementById("myRegister");
            var y = document.getElementById("myLogin");
            x.style.display = "none";
            y.style.display = "block";
        }
        function submitRegister() {
            // alert("注册成功!")
        }

 CSS 样式

接下来,我们需要为页面添加样式,以确保它在视觉上是吸引人的。将以下 CSS 代码保存在 styles.css 文件中:

* {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            width: 900px;
            height: 500px;
            background-color: rgba(255, 255, 255, 0.7);
            border-radius: 10px;
            margin: 10% auto;
            box-shadow: 0 0 10px 6px rgba(0, 0, 0, 0.1);
            position: relative;
            z-index: 1;
        }

        .box .left {
            width: 35%;
            height: 100%;
            position: absolute;
            z-index: 2;
            background-image: url(1.jpg);
            background-size: cover;
        }

        .register {
            position: absolute;
            width: 60%;
            height: 60px;
            color: #080808;
            background-color: transparent;
            font-size: 20px;
            border-radius: 5ch;
            border: 2px dotted #0984e3;
            margin: 70% 0 0 50%;
            transform: translateX(-50%);
        }

        .register:hover {
            color: #0984e3;
        }

        .box .right {
            display: flex;
            width: 65%;
            flex-direction: column;
            align-items: center;
        }

        .box .right h2 {
            color: #74b9ff;
            font-size: 50px;
            margin-top: 70px;
        }

        .box .right form {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
        }

        .box .right form .content {
            width: 100%;
            height: 50px;
            font-size: 20px;
            margin-top: 30px;
            padding: 10px 0 0 10px;
            border: none;
            border-bottom: 1px dotted #74b9ff;
            color: #74b9ff;
        }

        .right form .content:focus {
            outline: none;
            color: #74b9ff;
            padding: 10px 0 0 20px;
        }

        .right .submit {
            width: 60%;
            height: 60px;
            color: #f6f6f6;
            background-image: linear-gradient(120deg, #0984e3, #b1d2f6 100%);
            font-size: 20px;
            border-radius: 5ch;
            border: none;
            margin: 30px 0 0 50%;
            transform: translateX(-50%);
        }

        .right .submit:hover {
            box-shadow: 0 0 5px 5px rgba(20, 20, 20, 0.15);
        }

        .iconPhone {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/phone.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .iconPassword {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/password.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .iconUser {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/user.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .distant2 {
            margin-top: 35px;
        }

        .distant1 {
            margin-top: 50px;
        }

 完整代码

<!DOCTYPE html>
<html lang="zh-CN">

<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>登录页面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            width: 900px;
            height: 500px;
            background-color: rgba(255, 255, 255, 0.7);
            border-radius: 10px;
            margin: 10% auto;
            box-shadow: 0 0 10px 6px rgba(0, 0, 0, 0.1);
            position: relative;
            z-index: 1;
        }

        .box .left {
            width: 35%;
            height: 100%;
            position: absolute;
            z-index: 2;
            background-image: url(1.jpg);
            background-size: cover;
        }

        .register {
            position: absolute;
            width: 60%;
            height: 60px;
            color: #080808;
            background-color: transparent;
            font-size: 20px;
            border-radius: 5ch;
            border: 2px dotted #0984e3;
            margin: 70% 0 0 50%;
            transform: translateX(-50%);
        }

        .register:hover {
            color: #0984e3;
        }

        .box .right {
            display: flex;
            width: 65%;
            flex-direction: column;
            align-items: center;
        }

        .box .right h2 {
            color: #74b9ff;
            font-size: 50px;
            margin-top: 70px;
        }

        .box .right form {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
        }

        .box .right form .content {
            width: 100%;
            height: 50px;
            font-size: 20px;
            margin-top: 30px;
            padding: 10px 0 0 10px;
            border: none;
            border-bottom: 1px dotted #74b9ff;
            color: #74b9ff;
        }

        .right form .content:focus {
            outline: none;
            color: #74b9ff;
            padding: 10px 0 0 20px;
        }

        .right .submit {
            width: 60%;
            height: 60px;
            color: #f6f6f6;
            background-image: linear-gradient(120deg, #0984e3, #b1d2f6 100%);
            font-size: 20px;
            border-radius: 5ch;
            border: none;
            margin: 30px 0 0 50%;
            transform: translateX(-50%);
        }

        .right .submit:hover {
            box-shadow: 0 0 5px 5px rgba(20, 20, 20, 0.15);
        }

        .iconPhone {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/phone.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .iconPassword {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/password.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .iconUser {
            display: inline-block;
            height: 20px;
            width: 20px;
            background-image: url(img/user.svg);
            background-size: cover;
            /*这里放置图标的绝对路径*/
            background-repeat: no-repeat;
        }

        .distant2 {
            margin-top: 35px;
        }

        .distant1 {
            margin-top: 50px;
        }
    </style>
    <script>
        function toggleDivRegister() {
            var x = document.getElementById("myRegister");
            var y = document.getElementById("myLogin");
            x.style.display = "block";
            y.style.display = "none";
        }
        function toggleDivLogin() {
            var x = document.getElementById("myRegister");
            var y = document.getElementById("myLogin");
            x.style.display = "none";
            y.style.display = "block";
        }
        function submitRegister() {
            // alert("注册成功!")
        }
    </script>
    <link rel="icon" href="man.png">
</head>

<body>
    <div class="box">
        <div style=" width: 100%;height: 100%;">
            <div style="display: block;" id="myLogin" style="width: 100%;height: 100%;">
                <div class="left">
                    <button class="register" type="submit" onclick="toggleDivRegister()">去注册</button>
                </div>
                <div class="right" style="margin-left: 300px;">
                    <h2>登 录</h2>
                    <form action="">
                        <div style="width: 400px;">
                            <div>
                                <div style="display: flex;">
                                    <i class="iconPhone distant1"></i>
                                    <input class="content" type="phone" placeholder="手机号" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant1"></i>
                                    <input class="content" type="password" placeholder="密码" required>
                                </div>
                            </div>

                            <div style="padding: 10px;">
                                <span style="float: left;display: flex;justify-content: center;align-content: center;">
                                    <input type="checkbox" style="vertical-align:top;" /><span
                                        style="font-size: 14px;vertical-align:top;padding-left: 5px;">记住密码</span>
                                </span>
                                <span style="float: right;font-size: 15px;color: rgb(74, 159, 244);">忘记密码?</span>
                            </div>
                        </div>

                        <button class="submit" type="submit">登录</button>
                    </form>
                </div>
            </div>
            <div style="display: none;" id="myRegister" style="width: 100%;height: 100%;">
                <div class="left">
                    <button class="register" type="submit" onclick="toggleDivLogin()">去登录</button>
                </div>
                <div class="right" style="margin-left: 300px;">
                    <h2 style="color: #74b9ff;font-size: 50px;margin-top: 40px;">注 册</h2>
                    <form action="">
                        <div style="width: 400px;">
                            <div>
                                <div style="display: flex;">
                                    <i class="iconPhone distant2"></i>
                                    <input class="content" type="phone" placeholder="请输入手机号"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconUser distant2"></i>
                                    <input class="content" type="username" placeholder="请输入用户名"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant2"></i>
                                    <input class="content" type="password" placeholder="请输入密码"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                                <div style="display: flex;">
                                    <i class="iconPassword distant2"></i>
                                    <input class="content" type="password_reset" placeholder="请再次输入密码"
                                        style="height: 30px; padding-bottom: 10px;" required>
                                </div>
                            </div>
                        </div>

                        <button class="submit" type="submit" onclick="submitRegister()">立即注册</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>

</html>

实现效果

总结

在本教程中,我们创建了一个包含登录和注册功能的基本页面。通过 HTML 定义页面结构,使用 CSS 进行样式设计,并通过 JavaScript 实现页面功能,我们构建了一个功能完备的用户界面。这种基础的设计可以根据需要进一步扩展,例如添加表单验证、与后端 API 集成等。

希望这个详细的教程对您有所帮助!如果您有任何问题或建议,请在评论区留言,我们将尽快回复。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2042075.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

DALL-E 2:重新定义图像生成的人工智能

DALL-E 2是一款先进的人工智能模型&#xff0c;它在图像生成领域取得了突破性进展。与前一代DALL-E相比&#xff0c;DALL-E 2能够以更高的分辨率和更精细的细节生成图像&#xff0c;同时还能更好地理解并处理复杂的文本描述。这意味着&#xff0c;用户可以通过输入描述性的文本…

⌈ 传知代码 ⌋ Visual SLAM函数

&#x1f49b;前情提要&#x1f49b; 本文是传知代码平台中的相关前沿知识与技术的分享~ 接下来我们即将进入一个全新的空间&#xff0c;对技术有一个全新的视角~ 本文所涉及所有资源均在传知代码平台可获取 以下的内容一定会让你对AI 赋能时代有一个颠覆性的认识哦&#x…

【扩散模型入门教程】

DDPM 从零实现代码&#xff1a;https://huggingface.co/blog/annotated-diffusion improved-diffusion&#xff0c;openai代码&#xff1a;https://github.com/openai/improved-diffusion diffusion_tutorial&#xff1a;https://github.com/sunlin-ai/diffusion_tutorial St…

RCE多种绕过技巧+贷齐乐漏洞复现

文章目录 1、RCE绕过2、贷齐乐的漏洞复现3、函数绕过 1、RCE绕过 <?php if(isset($_GET[code])){$code $_GET[code];if(strlen($code)>35){die("Long.");}if(preg_match("/[A-Za-z0-9_$]/",$code)){die("NO.");}eval($code); }else{hig…

医疗挂号管理系统

TOC springboot203医疗挂号管理系统 第一章 绪论 1.1 选题背景 目前整个社会发展的速度&#xff0c;严重依赖于互联网&#xff0c;如果没有了互联网的存在&#xff0c;市场可能会一蹶不振&#xff0c;严重影响经济的发展水平&#xff0c;影响人们的生活质量。计算机的发展&…

51单片机-LCD1602显示屏

简介 是一个液晶显示屏&#xff0c;通过电压对显示区域进行控制&#xff0c;有电就显示。 能够同时显示32个字符&#xff0c;分为两行&#xff0c;一行显示16个字符。可以显示的内容只能是字母、数字或者一些特殊符号。 使用ASCII码来让LCD1602来显示对应的字符。 电路图 …

HarmonyOS应用三之组件生命周期和参数传递

目录&#xff1a; 1、生命周期的执行顺序2、页面数据传递3、图片的读取4、数据的备份和恢复5、轮播图6、页面布局图 1、生命周期的执行顺序 /** Copyright (c) 2023 Huawei Device Co., Ltd.* Licensed under the Apache License, Version 2.0 (the "License");* yo…

OpenSSL源码编译及Debug

** 1. 环境 Linux 5.19.0-14-generic 22.04.1-Ubuntu 2. 所需工具 gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04) cmake version 3.22.1 3. 步骤 3.1 获取openssl源码 方法可以git clone获得源码&#xff0c;或者直接去GitHub上下载压缩包&#xff0c;GitHub网址&#xf…

4 C 语言变量、printf 基本输出、scanf 基本输入、关键字、标识符及其命名规则

目录 1 为什么需要变量 2 变量的概念 3 变量的声明和使用 3.1 vscode 管理代码 4 printf 输出变量 5 scanf 输入数据赋值给变量 6 标识符 6.1 标识符命名规范 6.1.1 强制规范 6.1.2 建议规范 6.2 关键字 7 案例&#xff1a;求从键盘输入整数的和 8 测试题 1 为什么…

如何用20块钱创建一个国际网站 VC编程网站 www.vcbcw.top

我一直想弄一个网站。 但是网页设计这一块一直没有精力学习。 所以打算先用最少的投入创建一个属于自己的网站。 第一步&#xff1a; 到万网www.net.cn上申请一个域名&#xff0c;8块钱的&#xff0c;10块钱的都有&#xff0c;自己好好想一个名称就行了。 新手&#xff0c…

【重新定义matlab强大系列二十】Matlab显示地球地貌数据

&#x1f517; 运行环境&#xff1a;Matlab &#x1f6a9; 撰写作者&#xff1a;左手の明天 &#x1f947; 精选专栏&#xff1a;《python》 &#x1f525; 推荐专栏&#xff1a;《算法研究》 #### 防伪水印——左手の明天 #### &#x1f497; 大家好&#x1f917;&#x1f91…

探索Java Stream API:高效处理集合的利器

文章目录 一、Stream API简介1.1 什么是Stream&#xff1f;1.2 Stream的特点 二、Stream API的基本操作2.1 创建Stream2.2 中间操作2.3 终端操作 三、Stream API的高级应用3.1 并行Stream3.2 复杂数据处理3.3 Stream与Optional 四、最佳实践例子 1: 筛选和映射例子 2: 排序和收…

【Linux修行路】进程控制——程序替换

目录 ⛳️推荐 一、单进程版程序替换看现象 二、程序替换的基本原理 三、程序替换接口学习 3.1 替换自己写的可执行程序 3.2 第三个参数 envp 验证 ⛳️推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下…

Dify 开源大语言模型(LLM) 应用开发平台如何使用Docker部署与远程访问

目录 ⛳️推荐 前言 1. Docker部署Dify 2. 本地访问Dify 3. Ubuntu安装Cpolar 4. 配置公网地址 5. 远程访问 6. 固定Cpolar公网地址 7. 固定地址访问 ⛳️推荐 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享…

Vue3列表(List)

效果如下图&#xff1a;在线预览 APIs List 参数说明类型默认值bordered是否展示边框booleanfalsevertical是否使用竖直样式booleanfalsesplit是否展示分割线booleantruesize列表尺寸‘small’ | ‘middle’ | ‘large’‘middle’loading是否加载中booleanfalsehoverable是否…

mysql写个分区表

因为表量已经达到1个亿了。现在想做个优化&#xff0c;先按照 create_time 时间进行分区吧。 create_time 是varchar类型。 CREATE TABLE orders (id varchar(40) NOT NULL ,order_no VARCHAR(20) NOT NULL,create_time VARCHAR(20) NOT NULL,amount DECIMAL(10,2) NOT NULL,…

Unity如何使用Spine动画导出的动画

Unity如何使用Spine动画导出的动画 介绍使用版本Spine导出源文件修改Spine3.8.75版本导入Unity的3.8版本Spine的报错Unity辅助修改Json中版本号方式总结 介绍 最近公司在做抖音小程序的小游戏&#xff0c;我们这边动画部分使用的是spine动画&#xff0c;所以会有spine导入的问…

IDEA使用LiveTemplate快速生成方法注释

本文目标&#xff1a;开发人员&#xff0c;在了解利用Live Template动态获取方法输入输出参数、创建日期时间方法的条件下&#xff0c;进行自动生成方法注释&#xff0c;达到自动添加方法注释的程度&#xff1b; 文章目录 1 场景2 要点2.1 新增LiveTemplate模版2.2 模版内容填写…

FFMPEG推流器讲解

FFMPEG重要结构体的讲解 FFMPEG中有六个比较重要的结构体&#xff0c;分别是AVFormatContext、AVOutputFormat、 AVStream、AVCodec、AVCodecContext、AVPacket、AVFrame、AVIOContext结构体&#xff0c;这几个结构体是贯穿着整个FFMPEG核心功能。 AVFormatContext 这个结构…

基于web的大学生一体化服务平台的设计与实现

TOC springboot209基于web的大学生一体化服务平台的设计与实现 第1章 绪论 1.1 课题背景 二十一世纪互联网的出现&#xff0c;改变了几千年以来人们的生活&#xff0c;不仅仅是生活物资的丰富&#xff0c;还有精神层次的丰富。在互联网诞生之前&#xff0c;地域位置往往是人…