【发布时间】:2021-06-26 16:09:27
【问题描述】:
在这里,我正在尝试将带有幻灯片过渡的背景颜色添加到单选按钮。在活动背景色上移动幻灯片过渡。我尝试使用transform: translate();,但它不起作用。而且我不想更改 HTML。谁能建议我如何实现。
/** Case Switch Button **/
.case-switch-wrap h3 {
font-family: "Lato", Sans-serif;
font-size: 14px;
font-weight: 400;
line-height: 26px;
letter-spacing: 0.5px;
color: #000000;
}
.case-switch {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
/* height: 38px; */
width: 130px;
background: #e6e6e6;
border-radius: 3px;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0%), 0 1px rgba(255, 255, 255, 10%);
}
.switch-label {
padding-left: 65px;
position: relative;
z-index: 999999999;
}
.switch-label input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.switch-label .checkmark {
position: absolute;
top: 0;
left: 0;
height: 40px;
width: 65px;
background: #e6e6e6;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
border-radius: 4px;
}
.switch-label input:checked~.checkmark {
background: #39ccae;
color: #fff;
}
.switch-label input:checked~.text {
font-weight: bold;
}
<div class="case-switch">
<label class="switch-label switch-label-on">
<input type="radio" class="switch-input" name="switch-toggle" data-ref="on" checked>
<span class="checkmark">On</span>
</label>
<label class="switch-label switch-label-off">
<input type="radio" class="switch-input" name="switch-toggle" data-ref="off">
<span class="checkmark">Off</span>
</label>
</div>
【问题讨论】:
-
您需要翻译一些东西 - 不确定您尝试过的转换是什么。您是否考虑过使用伪元素作为被翻译的东西?
-
@AHaworth 不,我没有尝试使用伪元素。
-
@kinglish 的回答使用了一个伪元素 - 在为您提供翻译内容的同时,您不必创建更多 HTML。
标签: javascript html css css-transitions