博主信息
博文 14
粉丝 0
评论 0
访问量 13395
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
常用的"状态伪类"
陈翔
原创
555人浏览过

CSS

```

/* ! 状态伪类 */

fieldset {

  display: inline-grid;

  gap: 1em;

  border-radius: 10px;

  padding: 1em 2em;

  color: #666;

  background: linear-gradient(to left top, lightcyan, white);

}

fieldset legend {

  text-align: center;

}

fieldset input {

  padding: 5px;

  border: none;

  border-bottom: 1px solid #666;

  outline: none;

  background-color: transparent;

}

/* ! 表单状态伪类 */

/* ? 匹配获取到焦点的元素 */

fieldset :focus {

  background-color: lightgreen;

  transition: 0.4s;

}

/* ? 匹配被选中的复选框元素 */

input[type='checkbox']:checked + label {

  color: red;

}

/* ? 当鼠标悬停在某个元素上的效果 */

button {

  /* 去掉默认的边框与轮廓线 */

  border: none;

  outline: none;

  /* 重置默认字体与背景色 */

  background-color: seagreen;

  color: white;

  padding: 5px 10px;

  /* 文字少,可适当拉开字间距 */

  letter-spacing: 1em;

}

button:hover {

  cursor: pointer;

  /* 透明度 */

  opacity: 0.8;

  transition: 0.4s;

}

fieldset :disabled {

  background-color: yellow;

}

```

HTML:

```

<!DOCTYPE html>

<html lang="zh-CN">

  <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" />

    <link rel="stylesheet" href="css/fake-status.css" />

    <title>状态伪类选择器</title>

  </head>

  <body>

    <!-- ? 状态伪类: <a>, <form> -->

    <form action="">

      <fieldset>

        <legend>用户注册</legend>

        <!-- ? autofocus: 布尔属性,自动获取焦点 -->

        <input type="text" id="username" name="username" placeholder="用户名" required autofocus />

        <input type="email" id="email" name="email" placeholder="邮箱" required disabled />

        <input type="password" id="password" name="password" placeholder="密码" required />

        <!-- ? 复选框默认是选中状态: checked -->

        <div>

          <input type="checkbox" id="rem" name="remember" checked />

          <label for="rem">记住我</label>

        </div>

        <button>提交</button>

      </fieldset>

    </form>

  </body>

</html>

```

本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学