用HTML+CSS手写一个自定义表单

 html部分

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单</title>
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <form action="" class="container">
        <h1>用户注册</h1>
        <div class="formItem">
            <input class="txt" type="text" placeholder="请输入11位手机号" maxlength="11">
        </div>

        <div class="formItem clearfix captcha">
            <input class="txt left" type="text" placeholder="请填写验证码">
            <button class="right" type="button" disabled>发送验证码</button>
        </div>

        <div class="formItem">
            <input class="txt" type="password" placeholder="请输入密码">
        </div>
        <div class="formItem">
            <input class="txt" type="password" placeholder="请再次输入密码">
        </div>

        <div class="formItem">
            <select name="" id="" multiple class="txt">
                <option>爱好1</option>
                <option>爱好2</option>
                <option>爱好3</option>
                <option>爱好4</option>
                <option>爱好5</option>
                <option>爱好6</option>
                <option>爱好7</option>
                <option>爱好8</option>
                <option>爱好9</option>
                <option>爱好10</option>
            </select>
        </div>

        <div class="formItem clearfix">
            <div class="title left">性别</div>
            <div class="left">
                <label>
                    <input type="radio" checked name="sex">
                    <span>男</span>
                </label>
                <label>
                    <input type="radio" name="sex">
                    <span>女</span>
                </label>
            </div>
        </div>

        <div class="formItem">
            <textarea class="txt" name="" id="" placeholder="请填写个人简介"></textarea>
        </div>

        <div class="formItem policy">
            <label>
                <input type="checkbox" name="" id="">
                <span class="content">同意</span>
            </label>
        </div>

        <div class="formItem">
            <button>立即注册</button>
            <button type="reset">重置表单</button>
        </div>
    </form>
</body>

</html>

css部分 

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

html {
    background: #081623;
    color: #333;
}

.container {
    width: 400px;
    margin: 30px auto;
    border-radius: 10px;
    padding: 20px;
    background: #fff;
}

.container h1 {
    text-align: center;
    margin-bottom: 30px;
}

.formItem {
    margin-bottom: 10px;
}

/*设置文本框的统一样式*/
.txt {
    width: 100%;
    padding: 10px;
    border-radius: 5px;
    font-size: 14px;
    outline: none;
    height: 40px;
    border: 1px solid #ccc;
}

.txt:focus {
    border-color: #5f8be8;
}

select.txt {
    height: 100px;
    padding: 10px;
}

textarea.txt {
    resize: none;
    height: 100px;
    padding: 10px;
}

button {
    outline: none;
    border: none;
    height: 40px;
    width: 150px;
    font-size: 15px;
    border-radius: 5px;
    color: #fff;
    background-color: #5f8be8;
    cursor: pointer;
}

button:hover {
    background-color: #93b1f2;
}

button:disabled {
    background-color: #c8d5f1;
    cursor: not-allowed;
}

/*处理浮动元素*/
.left {
    float: left;
}

.right {
    float: right;
}

.clearfix::after {
    content: "";
    display: block;
    clear: both;
}

.captcha .txt {
    width: 170px;

}

.title {
    margin-right: 10px;
}

.policy .content {
    font-size: 12px;
    vertical-align: 2px;
}

label {
    cursor: pointer;
}

label span {
    color: #aaa;
}

label input:checked~span {
    color: #333;
}

input:focus::placeholder {
    color: #5f8be8;
}

效果展示 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值