首页前端开发CSScss开通关闭按钮组

css开通关闭按钮组

时间2023-11-15 14:26:03发布访客分类CSS浏览905
导读:CSS是网页设计中不可或缺的一环,它可以美化网页、调整网页布局和功能,同时也有助于提高用户体验和页面可访问性。在很多网页中,我们经常会看到一些开关按钮组,用来控制一些功能或显示内容,它们通常由两个按钮组成,一个是“开”,一个是“关”。下面我...

CSS是网页设计中不可或缺的一环,它可以美化网页、调整网页布局和功能,同时也有助于提高用户体验和页面可访问性。在很多网页中,我们经常会看到一些开关按钮组,用来控制一些功能或显示内容,它们通常由两个按钮组成,一个是“开”,一个是“关”。

下面我们来看一下如何用CSS实现一个开关按钮组:

/* HTML结构 */div class="switch">
      input type="checkbox" id="switch-1">
      label for="switch-1">
    /label>
    /div>
/* CSS样式 */.switch {
      position: relative;
      display: inline-block;
      width: 52px;
      height: 32px;
}
.switch input[type="checkbox"] {
      display: none;
}
.switch label {
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      width: 52px;
      height: 32px;
      border-radius: 16px;
      background-color: #ccc;
      cursor: pointer;
}
/* 开关打开状态样式 */.switch input[type="checkbox"]:checked + label {
      background-color: #4CAF50;
}
/* 开关打开状态增加圆形滑块 */.switch input[type="checkbox"]:checked + label::before {
      content: "";
      display: block;
      position: absolute;
      top: 2px;
      left: 2px;
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background-color: white;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
      transition: all 0.3s ease;
      transform: translateX(20px);
}
/* 开关关闭状态样式 */.switch label::after {
      content: "";
      display: block;
      position: absolute;
      top: 2px;
      left: 2px;
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background-color: white;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
      transition: all 0.3s ease;
}
.switch input[type="checkbox"]:checked + label::after {
      transform: translateX(20px);
      opacity: 0;
}
    

代码中用到了label标签,它的作用是可以使文本和表单元素关联起来,当用户点击文本时即可自动跳转到对应的表单元素。在这里,我们用label标签来创建一个自定义的开关按钮组,点击“开”或“关”即可切换样式。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: css开通关闭按钮组
本文地址: https://pptw.com/jishu/540393.html
css引入net err_aborted html代码在jsp中运行环境

游客 回复需填写必要信息