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: 设置占位符文本的颜色、字体大小、文本对齐和透明度。
相关推荐
好了来看下一题24 分钟前
TypeScript 项目配置
前端·javascript·typescript
江城开朗的豌豆27 分钟前
Vue的双向绑定魔法:如何让数据与视图‘心有灵犀’?
前端·javascript·vue.js
江城开朗的豌豆29 分钟前
Vue权限控制小妙招:动态渲染列表的优雅实现
前端·javascript·vue.js
@菜菜_达1 小时前
CSS a标签内文本折行展示
前端·css
霸王蟹1 小时前
带你手写React中的useReducer函数。(底层实现)
前端·javascript·笔记·学习·react.js·typescript·前端框架
托尼沙滩裤1 小时前
【Vue3】实现屏幕共享惊艳亮相
前端·javascript·vue.js
啃火龙果的兔子2 小时前
前端八股文-vue篇
前端·javascript·vue.js
孜然卷k2 小时前
前端处理后端对象类型时间格式通用方法封装,前端JS处理JSON 序列化后的格式 java.time 包中的日期时间类
前端·json
幼儿园技术家2 小时前
微信小程序实现用户进行推客的注册绑定
前端
gwcgwcjava2 小时前
[技术积累]成熟的前端和后端开发框架
前端