设计一个开关样式的双项单选按钮。

本文介绍如何使用HTML和CSS实现一个日期选择器,包括创建时间与接触时间两个选项,通过交互改变样式实现选中状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTML代码如下:

在一个DIV中:

   <div class="switch">
      <input type="radio" class="switch-input" name="seachdate_choose" value="ct" id="week" checked="checked" >
      <label for="week" class="switch-label switch-label-off">创建时间</label>
      <input type="radio" class="switch-input" name="seachdate_choose" value="st" id="month" >
      <label for="month" class="switch-label switch-label-on">接触时间</label>
      <span class="switch-selection"></span>
    </div>

CSS如下:


.switch {
  position: relative;

  height: 24px;
  width: 120px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 3px;
  -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
}

.switch-label {
  position: relative;
  z-index: 2;
  float: left;
  width: 58px;
  line-height: 24px;
  font-size: 11px;
  
  text-align: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0);
  cursor: pointer;
}



.switch-input {
  display: none;
}
.switch-input:checked + .switch-label {
  font-weight: bold;
  color: rgba(0, 0, 0, 0.65);
  text-shadow: 0 1px rgba(255, 255, 255, 0.25);
  -webkit-transition: 0.15s ease-out;
  -moz-transition: 0.15s ease-out;
  -o-transition: 0.15s ease-out;
  transition: 0.15s ease-out;
}
.switch-input:checked + .switch-label-on ~ .switch-selection {
  left: 60px;
  /* Note: left: 50% doesn't transition in WebKit */
}

.switch-selection {
  display: block;
  position: absolute;
  z-index: 1;
  top: 0px;
  left: 2px;
  width: 58px;
  height: 24px;
  background: #65bd63;
  border-radius: 3px;
  background-image: -webkit-linear-gradient(top, #83C4F0, #83C4F0);
  background-image: -moz-linear-gradient(top, #83C4F0, #83C4F0);
  background-image: -o-linear-gradient(top, #83C4F0, #83C4F0);
  background-image: linear-gradient(to bottom, #83C4F0, #83C4F0);
  -webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2);
  -webkit-transition: left 0.15s ease-out;
  -moz-transition: left 0.15s ease-out;
  -o-transition: left 0.15s ease-out;
  transition: left 0.15s ease-out;
}
.switch-blue .switch-selection {
  background: #3aa2d0;
  background-image: -webkit-linear-gradient(top, #4fc9ee, #3aa2d0);
  background-image: -moz-linear-gradient(top, #4fc9ee, #3aa2d0);
  background-image: -o-linear-gradient(top, #4fc9ee, #3aa2d0);
  background-image: linear-gradient(to bottom, #4fc9ee, #3aa2d0);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值