gpt4 book ai didi

html - 当我使用跨度时,有没有办法为我禁用的单选按钮设置样式

转载 作者:太空宇宙 更新时间:2023-11-04 05:36:15 25 4
gpt4 key购买 nike

我想让我的单选按钮变成方形,所以我查阅了一些 CSS 来实现,这基本上涉及到使用 span 和 before 和 after。但是现在我的客户希望禁用单选按钮并在禁用时具有不同的样式。然后我遇到了一个问题。因为我使用跨度,所以当我的单选按钮被禁用时,我无法真正设置它的样式。我可以用 CSS 解决这个问题吗?我可以用 javascript 切换样式,但我正在寻找 CSS 解决方案。

CSS

body {
background: #fbfbfb;
font-family: Arial;
font-weight: bold;
color: rgba(0, 0, 0, 0.7);
}

.radio-button
{
display: none;
}

.radio[disabled] {
display: none;
}

.radio-label {
display: inline-block;
padding: 5px 10px;
cursor: pointer;
}

.radio-label .radio-span {
position: relative;
line-height: 16px;
}

.radio-label .radio-span:before {
font-family: "FontAwesome";
content: "\f0c8";
display: inline-block;
padding-right: 3px;
vertical-align: middle;
font-weight: 900;
}

.radio-label .radio-span:after {
position: absolute;
top: 1px;
left: 0px;
transition: 300ms;
opacity: 0;
font-family: "FontAwesome";
content: "\f00c";
display: inline-block;
padding-right: 3px;
vertical-align: middle;
font-weight: 900;
}

.radio-label .radio-button:checked+.radio-span:after {
opacity: 1;
}

/*
.radio-span needs to have this style when the radio button is disabled
{
font-family: "FontAwesome";
content: "\f04d";
display: inline-block;
padding-right: 3px;
vertical-align: middle;
font-weight: 900;
} */

HTML

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./style.css">

<script src="https://kit.fontawesome.com/mycode.js" crossorigin="anonymous"></script>
</head>
<body>
<form>
<label class="radio-label"><input id="toDisable" type="radio" name="gender" value="male" class="radio-button"> <span class="radio-span"> Male </span></label></br>
<label class="radio-label"><input type="radio" name="gender" value="female" class="radio-button"> <span class="radio-span"> Female </span> </label></br>
<label class="radio-label"><input type="radio" name="gender" value="other" class="radio-button"> <span class="radio-span"> Other </span></label> </br>
</form>
<script>
document.getElementById("toDisable").disabled = true;
</script>
</body>
</html>

最佳答案

由于您的 span 跟随单选按钮的 sibling ,因此选择器可能是

.radio-button[disabled] + span {
...
}

input 元素上使用 disabled 属性

关于html - 当我使用跨度时,有没有办法为我禁用的单选按钮设置样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59628762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com