required和optional表单案例

CSS
在这里插.clearfix::after {
            content: "";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }

        .clearfix {
            *zoom: 1;
        }

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

        input:required,
        textarea:required {
            border-right: 3px solid #aa0088;
        }

        input:optional,
        select:optional {
            border-right: 3px solid #999;
        }

        input:required+label::after {
            content: "(必填)";
        }

        input:optional+label::after {
            content: "(选填)";
        }

        input:focus,
        select:focus,
        textarea:focus {
            outline: 0;
        }

        input:required:focus,
        textarea:required:focus {
            box-shadow: 0 0 3px 1px #aa0088;
        }

        input:optional:focus,
        select:optional:focus {
            box-shadow: 0 0 3px 1px #999;
        }

        .container {
            max-width: 400px;
            margin: 20px auto;
            /* border: 1px solid #999; */
        }

        input,
        select,
        textarea {
            width: 240px;
            margin: 10px 0;
            padding: .5em .1em;
            border: 1px solid #999;
        }

        label {
            margin-left: 10px;
            color: #999;
        }

        input[type="submit"] {
            background-color: #cc00aa;
            border: 1px solid #aa0088;
            padding: 10px 0;
            color: #fff;
        }

        input[type="submit"]:hover {
            cursor: pointer;
            background-color: #aa0088;
        }入代码片
HTML
<div class="container">
        <form action="#">
            <input type="name" id="name" required><label for="name">名称</label>
            <input type="email" id="email" required><label for="email">邮箱</label>
            <input type="tel" name="" id="tel"><label for="tel">手机</label>
            <input type="url" name="" id="url"><label for="url">网址</label>
            <select name="#" id="">
                <option value="1">非必填选项1</option>
                <option value="2">非必填选项2</option>
                <option value="3">非必填选项3</option>
                <option value="4">非必填选项4</option>
            </select>
            <textarea name="" id="" cols="30" rows="10" placeholder="留言(必填)" required></textarea>
            <input type="submit" value="提交表单">
        </form>
    </div>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值