当前位置: 首页 > news >正文

前端项目3-01:登录页面

一、效果图

二、全部代码

<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>码农魔盒</title><style>.bg{position: fixed;top: 0;left:0;object-fit: cover;width: 100vw;height: 100vh;}.box{width: 950px;height: 450px;box-shadow: 0 5px 15px rgba(0,0,0,.8);display: flex;position: fixed;top: 50%;left:50%;transform: translate(-50%,-50%);box-sizing: border-box;padding: 20px;background: rgba(47,1,74,.8);}.left{width: 65%;}.left>img{display: block;width: 100%;height: 100%;object-fit: cover;}.right{width: 35%;height: 100%;box-sizing: border-box;padding: 0 20px;}h1{color: #fff;text-align: center;margin-top: 45px;}.inputItem{height: 44px;padding: 0;padding-left: 8px;border: none;background: #fff;outline: none;width: 100%;font-size: 16px;margin-top: 20px;}.btn{background: linear-gradient(to right,#65CBF7,#B3A5FC);box-shadow: 0 5px 15px rgba(255, 255, 255, .6);color: #9C3493;font-weight: bold;border: none;border-radius: 30px;height: 46px;width: 100%;font-size: 18px;display: block;margin: auto;margin-top: 50px;}</style></head><body><img src="img/bg.jpg" alt="" class="bg"><div class="box"><div class="left"><img src="img/bg.jpg" alt=""></div><div class="right"><h1>用户登录</h1><input type="text" class="inputItem" placeholder="请输入账号"><input type="password" class="inputItem" placeholder="请输入密码"><button class="btn">登录</button></div></div></body>
</html>

三、代码详解

.bg{position: fixed;top: 0;left:0;object-fit: cover;width: 100vw;height: 100vh;
}
  • position: fixed:固定定位,相对于浏览器窗口

  • top:0; left:0:从左上角开始

  • object-fit: cover:图片覆盖整个区域,可能会裁剪

  • 100vw/100vh:占满整个视口宽度和高度

.box{width: 950px;height: 450px;box-shadow: 0 5px 15px rgba(0,0,0,.8);display: flex;position: fixed;top: 50%;left:50%;transform: translate(-50%,-50%);box-sizing: border-box;padding: 20px;background: rgba(47,1,74,.8);
}
  • box-shadow:添加阴影效果,增强立体感

  • display: flex:使用 Flexbox 布局

  • top:50%; left:50%:定位到页面中心

  • transform: translate(-50%,-50%):向上向左移动自身宽高的 50%,实现精确居中

  • box-sizing: border-box:让内边距包含在元素总宽高内

  • rgba(47,1,74,.8):半透明深紫色背景

.left{width: 65%;
}
.left>img{display: block;width: 100%;height: 100%;object-fit: cover;
}
  • .left:左侧区域占 65% 宽度

  • display: block:将图片转为块级元素

  • object-fit: cover:图片覆盖整个区域

.right{width: 35%;height: 100%;box-sizing: border-box;padding: 0 20px;
}
  • .right:右侧区域占 35% 宽度

  • padding: 0 20px:左右内边距 20px

h1{color: #fff;text-align: center;margin-top: 45px;
}
  • color: #fff:白色文字

  • text-align: center:文字居中对齐

  • margin-top: 45px:顶部外边距 45px

.inputItem{height: 44px;padding: 0;padding-left: 8px;border: none;background: #fff;outline: none;width: 100%;font-size: 16px;margin-top: 20px;
}
  • height: 44px:统一高度 44px

  • padding-left: 8px:左侧内边距 8px

  • border: none:无边框

  • outline: none:取消聚焦时的默认边框

  • width: 100%:宽度占满父容器

.btn{background: linear-gradient(to right,#65CBF7,#B3A5FC);box-shadow: 0 5px 15px rgba(255, 255, 255, .6);color: #9C3493;font-weight: bold;border: none;border-radius: 30px;height: 46px;width: 100%;font-size: 18px;display: block;margin: auto;margin-top: 50px;
}
  • linear-gradient:从左到右的渐变色背景

  • box-shadow:白色半透明阴影

  • color: #9C3493:深紫色文字

  • border-radius: 30px:圆角边框

  • margin: auto:水平居中

  • margin-top: 50px:顶部外边距 50px

相关文章:

  • 教程 | 一键批量下载 Dify「Markdown 转 Docx」生成的 Word 文件(附源码)
  • 服务器的安装与安全设置
  • 机器学习18-强化学习RLHF
  • Excel基础:数据编辑
  • git 多用户管理 跨平台
  • dify小用
  • Miniconda+Jupyter+PyCharm初始环境配置
  • Linux命令:内置命令与外部命令的本质区别
  • 开疆智能CCLinkIE转ModbusTCP网关连接测联无纸记录仪配置案例
  • 60% 重构项目陷 “越改越烂” 泥潭!
  • 【stm32】HAL库开发——CubeMX配置外部中断和配置PWM
  • Flink部署与应用——Flink架构概览
  • 【机器学习深度学习】线性代数
  • 爬虫简单实操2——以贴吧为例爬取“某吧”前10页的网页代码
  • 华为交换机 USG6311E 新建 vlan
  • python的银行柜台管理系统
  • 大模型在慢性病毒性肝炎预测及诊疗方案制定中的应用研究
  • window显示驱动开发—支持 DXGI DDI(四)
  • 6月份最新代发考试战报:思科华为HCIP HCSE 考试通过
  • C语言专题:15.宏定义与控制指令(#define、#ifndef、#undef、#defined)