css自定义单选框和开关选择器

52 篇文章 0 订阅
23 篇文章 0 订阅

一、自定义单选框

.icon {
	width: 30rpx;
	height: 30rpx;
	padding: 4rpx;
	border-radius: 50%;
	border: 1rpx solid #c4c4c4;
	background-clip: content-box;
	&.active {
		background-color: #6175F4;
		border-color: #6175F4;
	}
}

使用

<view class="personal-item dis-flex justify-between align-center">
  <text class="text-gray3 f28 fw700">性别</text>
  <view class="w70 fw500 dis-flex align-center justify-end">
    <view class="inline-flex f28 text-main fw500 ml40 align-center" @tap.stop="gender = 0">
	  <view class="icon" :class="{'active': gender==0}"></view>
	    <text class="ml10 f28">先生</text>
	  </view>
	  <view class="inline-flex f28 text-main fw500 ml40 align-center" @tap.stop="gender = 1">
	    <view class="icon" :class="{'active': gender==1}"></view>
		  <text class="ml10 f28">女士</text>
		</view>
	</view>
  </view>
</view>

二、自定义开关选择器

.label-swith{
	width: 106rpx;
	height: 41rpx;
	background: #F1F1F1;
	border-radius: 21rpx;
	position: relative;
	.on-off{
		width: 35rpx;
		height: 35rpx;
		background: #FFFFFF;
		border: 1px solid #E9E9E9;
		border-radius: 50%;
		position: absolute;
		top: 3rpx;
		left: 4rpx;
		right: 0;
		bottom: 0;
		transition-duration: .2s;
		transition-timing-function: ease;
		transition-property: all;
		transform: translateX(0%);
		
		&.active {
			position: absolute;
			background: #6477F4;
			border: 2rpx solid #FFFFFF;
			right: 4rpx;
			opacity: 0;
			opacity: 1;
			transform: translateX(170%);
		}
	}
}		

使用

<view class="label-swith" @click="switchChange">
  <view class="on-off" :class="{active:show}"></view>
</view>

show: false,   // 开关

switchChange() {
  this.show=!this.show
},

 

 三、修改复选框样式
 


checkbox.round .wx-checkbox-input {
  border-radius: 50%;/* 圆角 */
  width: 26rpx;
  height: 26rpx;
}

/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
checkbox.round .wx-checkbox-input.wx-checkbox-input-checked{
  background: $colorPrimary;
  border-color: $colorPrimary;
}

/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
checkbox.round .wx-checkbox-input.wx-checkbox-input-checked::before{
  border-radius: 50%;                            /* 圆角 */
  width: 26rpx;                                  /* 选中后对勾大小,不要超过背景的尺寸 */
  height: 26rpx;                                 /* 选中后对勾大小,不要超过背景的尺寸 */
  line-height: 26rpx;
  text-align: center;
  font-size: 20rpx;                             /* 对勾大小 26rpx */
  color: #fff;                                /* 对勾颜色 白色 */
  background: transparent;
  transform: translate(-50%, -50%) scale(1);
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值