HTML&CSS:领导说这个表单很不错,快来体验吧

这段代码是一个简单的HTML页面,它包含了一些CSS样式来美化两个输入框(用于用户名和密码)

演示效果

HTML&CSS

html 复制代码
<!DOCTYPE html>
<html lang="en">

<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>前端Hardy</title>
    <style>
        body {
            background-color: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            height: 100vh;
        }

        .container {
            width: 500px;
            height: 260px;
            background-color: #212121;
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
        }

        .inputGroup {
            font-family: 'Segoe UI', sans-serif;
            margin: 1em 0 1.5em 0;
            max-width: 190px;
            position: relative;
        }

        .inputGroup input {
            font-size: 100%;
            padding: 0.8em;
            outline: none;
            border: 2px solid rgb(200, 200, 200);
            background-color: transparent;
            border-radius: 20px;
            width: 100%;
            color: #fff;
        }

        .inputGroup label {
            font-size: 100%;
            position: absolute;
            left: 0;
            margin-left: 0.5em;
            pointer-events: none;
            transition: all 0.3s ease;
            color: #fff;
        }

        .inputGroup :is(input:focus, input:valid)~label {
            transform: translateY(-200%) scale(.9);
            margin: 0em;
            margin-left: 1.3em;
            padding: 0.4em;
            background-color: #212121;
        }

        .inputGroup :is(input:focus, input:valid) {
            border-color: rgb(150, 150, 200);
        }

        input::placeholder {
            color: #fff;
            font-size: 12px;
            text-align: center;
            opacity: 0.8;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="inputGroup">
            <input type="text" required="" autocomplete="off" placeholder="输入用户名">
            <label for="name">用户名</label>
        </div>
        <div class="inputGroup">
            <input type="text" required="" autocomplete="off" placeholder="输入密码">
            <label for="name">密码</label>
        </div>
    </div>


</body>

</html>
  • container: 一个容器,用于居中显示输入框。设置容器的尺寸、背景颜色、圆角和布局。
  • inputGroup: 包含一个输入框和标签的组。设置输入组的字体、边距和最大宽度。
  • input type="text": 用户名输入框,设置为必填且不允许浏览器自动填充。
  • label for="name": 用户名的标签,用于提高可访问性。
  • inputGroup:包含密码输入框和标签,结构与用户名输入框相同
  • .inputGroup input: 设置输入框的字体大小、内边距、边框和背景颜色。
  • .inputGroup label: 设置标签的字体大小、位置和过渡效果。
  • .inputGroup :is(input:focus, input:valid)~label: 当输入框获得焦点或输入有效时,改变标签的位置、大小和背景颜色。
  • .inputGroup :is(input:focus, input:valid): 当输入框获得焦点或输入有效时,改变边框颜色。
  • input::placeholder: 设置占位符文本的颜色、字体大小、文本对齐和透明度。
相关推荐
前端付豪10 分钟前
实现必要的流式输出(Streaming)
前端·后端·agent
张元清13 分钟前
useMediaQuery:React 响应式设计完全指南
前端·javascript·面试
小金鱼Y13 分钟前
一文吃透 JavaScript 防抖:从原理到实战,让你的页面不再 “手抖”
前端·javascript·面试
Z兽兽17 分钟前
React 18 开发环境下useEffect 会执行两次,原因分析及解决方案
前端·react.js·前端框架
紫_龙18 分钟前
最新版vue3+TypeScript开发入门到实战教程之Vue3详解props
前端·vue.js·typescript
树上有只程序猿25 分钟前
这波低代码热,能维持多久
前端
姓王名礼30 分钟前
这是一个完整的全栈交付包,包含Vue3 前端交互界面(集成数字人视频流、ECharts 图表、语音对话)和Docker Compose 一键部署脚本。
前端·docker·echarts
嵌入式-老费34 分钟前
vivado hls的应用(axis接口)
前端·webpack·node.js
孟陬41 分钟前
国外技术周刊第 2 期 — 本周热门 🔥 YouTube 视频 TED 演讲 AI 如何能够拯救(而非摧毁)教育
前端·后端·程序员
小飞大王6661 小时前
从零手写 React:深度解析 Fiber 架构与 Hooks 实现
前端·react.js·架构