0
I have the following css:
@charset "utf-8";
/* CSS Document */
.divCheckBox {
width: 140px;
height: 34px;
}
.divCheckBox .valor {
display: inline-block;
line-height: 34px;
top: 0;
}
.divCheckBox .checkBox {
display: none;
}
.divCheckBox .labelCheckBox {
width: 60px;
height: 34px;
background-color: #CCC;
display: block;
cursor: pointer;
border-radius: 34px;
display: inline-block;
}
.divCheckBox .labelCheckBox:before {
width: 26px;
height: 26px;
margin: 4px;
background-color: #FFF;
content: "";
display: inline-block;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
vertical-align: middle;
}
.divCheckBox .checkBox:checked + .divCheckBox .labelCheckBox {
background-color: blue;
}
.divCheckBox .checkBox:checked + .divCheckBox .labelCheckBox:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
And the following html
<!DOCTYPE html>
<html>
<head>
<title>CheckBox Round</title>
<link type="text/css" rel="stylesheet" href="_css/checkBoxRound.css" />
</head>
<body>
<form action="?" method="post">
<div class="divCheckBox">
<label class="valor">SIM</label>
<input type="checkbox" name="ca" id="ca" class="checkBox">
<label for="ca" class="labelCheckBox"></label>
<label class="valor">NÃO </label>
</div>
<br />
<input type="submit">
</form>
</body>
</html>
When I spin, and I click on the labelCheckBox, technically I should change its color to blue and the inner ball run to the right. But it’s not happening.
However, although the class name is correct, in case I withdraw
.divCheckBox
Of the structure below
.divCheckBox .checkBox:checked + .divCheckBox .labelCheckBox {
background-color: blue;
}
.divCheckBox .checkBox:checked + .divCheckBox .labelCheckBox:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
Staying,
.checkBox:checked + .labelCheckBox {
background-color: blue;
}
.checkBox:checked + .labelCheckBox:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
So it works.
Where is that mistake?
That’s right. Thank you very much.
– Carlos Rocha