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: 设置占位符文本的颜色、字体大小、文本对齐和透明度。
相关推荐
Σίσυφος19001 小时前
halcon 条形码、二维码识别、opencv识别
前端·数据库
学代码的小前端1 小时前
0基础学前端-----CSS DAY13
前端·css
css趣多多2 小时前
案例自定义tabBar
前端
engchina3 小时前
@media 的常用场景与示例
css·media
姑苏洛言3 小时前
DeepSeek写微信转盘小程序需求文档,这不比产品经理强?
前端
林的快手4 小时前
CSS列表属性
前端·javascript·css·ajax·firefox·html5·safari
匹马夕阳4 小时前
ECharts极简入门
前端·信息可视化·echarts
API_technology4 小时前
电商API安全防护:JWT令牌与XSS防御实战
前端·安全·xss
yqcoder4 小时前
Express + MongoDB 实现在筛选时间段中用户名的模糊查询
java·前端·javascript
十八朵郁金香5 小时前
通俗易懂的DOM1级标准介绍
开发语言·前端·javascript