首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >零基础学习CSS(6)——:enabled、:disabled、:checked、:requeired、:optional、:defaul

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

作者头像
Dragon水魅
发布2026-01-23 18:59:53
发布2026-01-23 18:59:53
860
举报
官方资料

鱼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 选择器用于匹配启用和禁用的元素(大多在表单中匹配):

代码语言:javascript
复制
<!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
image.png

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

代码语言:javascript
复制
<!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
image.png

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

代码语言:javascript
复制
<!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 选择器用于修改默认元素的样式:

代码语言:javascript
复制
<!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
image.png
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2026-01-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 官方资料
  • 学习正文
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档