零基础学习CSS(6)——:enabled、:disabled、:checked、:requeired、:optional、:defaul

官方资料

鱼C课程案例库:https://ilovefishc.com/html5/
html5速查手册:https://man.ilovefishc.com/html5/
css速查手册:https://man.ilovefishc.com/css3/

学习正文

:enabled 选择器:https://man.ilovefishc.com/pageCSS3/dotenabled.html
:disabled 选择器:https://man.ilovefishc.com/pageCSS3/dotDisabled.html
:checked 选择器:https://man.ilovefishc.com/pageCSS3/dotChecked.html
:requeired 选择器:https://man.ilovefishc.com/pageCSS3/dotRequired.html
:optional 选择器:https://man.ilovefishc.com/pageCSS3/dotOptional.html
:default 选择器:https://man.ilovefishc.com/pageCSS3/dotDefault.html

:enabled 选择器和 disabled 选择器用于匹配启用和禁用的元素(大多在表单中匹配):

<!DOCTYPE html>
<html>
<head>
    <title>伪类选择器</title>
    <meta charset="utf-8">
    <style type="text/css">
        /* 设置禁用与可用的样式 */
        :enabled {
            outline: 1px solid green;;
        }

        :disabled {
            background-color: #dddddd;
        }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="enabled">可用:</label>
            <input type="text" name="enabled">
        </p> 
        <p>     
            <label for="disabled">禁用:</label>
            <input type="text" name="disabled" disabled>
        </p> 
        <button>可用按钮</button>
        <button disabled>不可用按钮</button>
    </form>
</body>
</html>

image.png

:check 选择器用于修改选中表单元素(单选、多选、下拉)的样式:

<!DOCTYPE html>
<html>
<head>
    <title>伪类选择器</title>
    <meta charset="utf-8">
    <style type="text/css">
    /* 设置表单元素的选项被选中时的样式 */
        :checked {
            height: 50px;
            width: 50px;
        }
    </style>
</head>
<body>
    <form>
       <input type="radio" name="gender" value="male"><span>男人</span><br>
       <input type="radio" name="gender" value="femele"><span>女人</span><br>
       <hr>
       <input type="checkbox" name="fruit" value="egg"><span>鸡蛋</span><br>
       <input type="checkbox" name="fruit" value="apple"><span>苹果</span><br>
       <input type="checkbox" name="fruit" value="banana"><span>香蕉</span><br>
    </form>
</body>
</html>

image.png

:required 选择器和 :optional 选择器用于设置必填和可选的样式:

<!DOCTYPE html>
<html>
<head>
    <title>伪类选择器</title>
    <meta charset="utf-8">
    <style type="text/css">
    /* 设置必填和可选的样式 */
        :required {
            outline: 3px solid red;
        }
        :optional {
            outline: 3px solid green;;
        }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="required">必填:</label>
            <input type="text" name="required" required>
        </p>
        <p>
            <label for="potional">可选:</label>
            <input type="text" name="potional">
        </p>
        <button type="submit">提交</button>
    </form>
</body>
</html>

在这里插入图片描述

:default 选择器用于修改默认元素的样式:

<!DOCTYPE html>
<html>
<head>
    <title>伪类选择器</title>
    <meta charset="utf-8">
    <style type="text/css">
    /* 设置默认元素的样式 */
        :default {
            outline: 3px solid red;
        }
    </style>
</head>
<body>
    <form>
        <p>
            <label for="required">必填:</label>
            <input type="text" name="required" required>
        </p>
        <p>
            <label for="potional">可选:</label>
            <input type="text" name="potional">
        </p>
        <button type="submit">提交</button>
    </form>
</body>
</html>

image.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值