В следующем фрагменте кода я не уверен, каким образом я получаю «невыбранные» N и Y, чтобы иметь больший контраст, учитывая, что над ним расположена серая горизонтальная таблетка. В приведенном ниже примере красный фон позволяет вам видеть N и Y, но если фрагмент помещен на серый фон, вы можете увидеть, что проблема в большей степени.
Я открыт для Перестройка синтаксиса html.
Сама таблетка не обязательно нуждается в прозрачности.
body,
html {
box-sizing: border-box;
background-color: red;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
.switch__input,
.switch__label {
position: absolute;
top: 0;
left: 0;
width: 90px;
height: 50px;
opacity: 0;
z-index: 0;
}
.switch__label {
z-index: 2;
opacity: 1;
}
.switch__label:before {
content: "";
text-align: center;
position: absolute;
top: 5px;
left: 0;
width: 90px;
height: 35px;
background-color: rgba(225, 225, 225, 0.5);
border-radius: 100px;
z-index: 0;
-webkit-transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.switch__label:after {
content: "";
position: absolute;
text-align: center;
font-size: 24px;
padding: 4.4px 0;
top: -2px;
left: 0;
width: 50px;
height: 50px;
background-color: grey;
border-radius: 100px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
z-index: 0;
-webkit-transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
-webkit-transition-property: left, background-color;
transition-property: left, background-color;
}
.switch__input:checked+.switch__label:before {
background-color: rgba(225, 225, 225, 0.5);
}
.switch__input:checked+.switch__label:after {
left: 40px;
background-color: #2d95e5;
}
.falsetruecontainer {
font-family: sans-serif;
display: flex;
width: 70px;
justify-content: space-evenly;
align-content: center;
font-size: 24px;
}
.n-circle {
position: relative;
color: black !important;
z-index: 1;
right: 3px;
}
.y-circle {
position: relative;
color: black !important;
z-index: 1;
left: 8px;
}
.switch__input:checked+.switch__label+.falsetruecontainer>.n-circle {}
.switch__input:checked+.switch__label+.falsetruecontainer>.y-circle {
content: 'Y';
z-index: 4;
color: #fff;
}
.switch__input:checked+.switch__label+.falsetruecontainer>.y-circle:after {
content: 'Y';
z-index: 4;
color: #fff;
}
.switch__input:checked+.switch__label+.falsetruecontainer>.n-circle:after {
content: 'N';
z-index: 3;
color: #fff;
}
.switch__input:not(:checked)+.switch__label+.falsetruecontainer>.n-circle {
content: 'N';
z-index: 4;
}
.switch__input:not(:checked)+.switch__label+.falsetruecontainer>.n-circle:before {
content: 'N';
z-index: 4;
color: white;
}
.switch__input:not(:checked)+.switch__label+.falsetruecontainer>.y-circle:before {
content: 'Y';
z-index: 4;
color: #fff;
}
<div class="switch">
<input type="checkbox" id="switch1" class="switch__input">
<label for="switch1" class="switch__label"></label>
<div class="falsetruecontainer">
<div class="n-circle"></div>
<div class="y-circle"></div>
</div>
</div>