关于radio 修改样式问题

本文介绍了一种在不支持伪元素和checked属性的IE8浏览器中实现自定义样式的Radio Button的方法。通过使用JavaScript和特定的CSS技巧,如PIE.htc文件,可以实现在现代浏览器和IE8中一致的视觉效果。

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

谷歌下: 页面和css如下

	<!-- 选项按钮 -->
		<div style="overflow: auto; margin-left: 26%; margin-top: 2%;">
			<div class="label-bth" style="margin-left: 3%;">
				<label class="test-label"><input class="test-radio" checked
					name="Fruit" type="radio" value="01" id="qy"  />
					<span class="test-radioInput" onclick="qy();"></span>企业 </label>
			</div>

			<div class="label-bth" style="margin-left: 8%;">
				<label class="test-label"><input class="test-radio"
					name="Fruit" type="radio" value="02" id="zrr"  />
					 <span class="test-radioInput" onclick="zrr();"></span>自然人 </label>
			</div>
		</div>

.test-label { display: inline-block; color: #fff; min-width:80px; } .test-radio { display: none } .test-radioInput { background-color: #fff; border-radius: 100%; display: inline-block; height: 16px; margin-right: 10px; margin-top: -1px; vertical-align: middle; width: 16px; line-height: 1; } .test-radio:checked+.test-radioInput:after{ background-color: #52C2F8; border-radius: 100%; content: ""; display: inline-block; height: 12px; margin: 2px; width: 12px; }   

 页面效果如下:

                                                                                                                                                                                                                                                                                      

由于要兼容ie8  所以 ie8 对伪元素和checked属性都不认识 所以加入了js

css修改为

.test-label {
	display: inline-block;
	color: #fff;
	min-width:80px;
}


.test-radio {
	display: none
}

.test-radioInput {
	background-color: #fff;
	border-radius: 100%;
	display: inline-block;
	height: 16px;
	margin-right: 10px;
	margin-top: -1px;
	vertical-align: middle;
	width: 16px;
	line-height: 1;
	
	behavior: url(/sjfwpt/swxxgxpt/swxxgxpt001/PIE.htc);
} 
//关于伪元素的部分注释掉
 /* .test-radio:checked+.test-radioInput:after{
	background-color: #52C2F8;
	border-radius: 100%;
	content: "";
	display: inline-block;
	height: 12px;
	margin: 2px;
	width: 12px;
	behavior: url(/sjfwpt/swxxgxpt/swxxgxpt001/PIE.htc);
} */ 

 js

function qy(){
	$("#qy").parent().find('span.test-radioInput').css({"display": "inline-block","backgroundColor": "#52C2F8"});
	$("#zrr").parent().find('span.test-radioInput').css({"display": "inline-block","backgroundColor": "#FFF"});
}
function zrr(){
	$("#zrr").parent().find('span.test-radioInput').css({"display": "inline-block","backgroundColor": "#52C2F8"});
	$("#qy").parent().find('span.test-radioInput').css({"display": "inline-block","backgroundColor": "#FFF"});
}
$(function(){ //进入页面默认选择的是企业 颜色变色 $("#qy").parent().find('span.test-radioInput').css({"display": "inline-block","backgroundColor": "#52C2F8"}); })

  

 

转载于:https://www.cnblogs.com/ylboke/p/9685214.html

修改 `el-radio` 组件的样式,可以使用以下方法: 1. 使用 CSS 全局样式修改 可以在全局样式文件中添加以下 CSS 代码,来修改 `el-radio` 组件的样式: ```css /* 选中状态下的圆点颜色 */ .el-radio__input.is-checked .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选中状态下的圆点颜色 */ .el-radio__input:not(.is-checked) .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } ``` 2. 使用 `>>>` / `/deep/` / `::v-deep` 选择器修改 可以在组件所在的页面或组件内部的 `<style>` 标签中,使用 `>>>` / `/deep/` / `::v-deep` 选择器来修改 `el-radio` 组件的样式。例如: ```html <template> <div> <el-radio v-model="radio" label="1">选项一</el-radio> <el-radio v-model="radio" label="2">选项二</el-radio> </div> </template> <style scoped> /* 使用 >>> 选择器修改 */ /* 选中状态下的圆点颜色 */ .el-radio__input.is-checked >>> .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选中状态下的圆点颜色 */ .el-radio__input:not(.is-checked) >>> .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } /* 使用 /deep/ 选择器修改 */ /* 选中状态下的圆点颜色 */ .el-radio__input.is-checked /deep/ .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选中状态下的圆点颜色 */ .el-radio__input:not(.is-checked) /deep/ .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } /* 使用 ::v-deep 选择器修改 */ /* 选中状态下的圆点颜色 */ .el-radio__input.is-checked ::v-deep .el-radio__inner { background-color: #ff0000; /* 修改为红色 */ } /* 未选中状态下的圆点颜色 */ .el-radio__input:not(.is-checked) ::v-deep .el-radio__inner::after { background-color: #00ff00; /* 修改为绿色 */ } /* 文字颜色 */ .el-radio__label { color: #0000ff; /* 修改为蓝色 */ } </style> ``` 以上就是两种修改 `el-radio` 组件样式的方法。其中,使用 CSS 全局样式修改的方法会影响到整个项目中所有使用到 `el-radio` 组件的样式,而使用 `>>>` / `/deep/` / `::v-deep` 选择器修改的方法只会影响到当前页面或组件中的 `el-radio` 组件的样式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值