Как подвинуть круг в следующем переключателе?
Есть следующий переключатель
Вот что получилось с ним сделать
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: black;
}
.radio-btn {
max-width: 40px;
min-height: 16px;
margin-top: 15px;
margin-left: 15px;
}
.radio-btn input {
display: none;
}
.radio-btn input:checked + label {
background: #D012FF;
box-shadow: 0 -18px 20px -12px #0B9090 inset;
}
.radio-btn input:checked + .circle {
transform: translateX(3px);
}
.radio-btn .btn-field {
transition: all 300ms;
background: #D9D9D9;
max-width: 40px;
min-height: 16px;
border-radius: 5px;
display: grid;
position: relative;
}
.radio-btn .btn-field .circle {
position: absolute;
top: -3px;
left: -2.42px;
width: 22.42px;
height: 22.98px;
background: linear-gradient(180deg, #A00BC5 0%, #1B5454 100%);
border: 3px solid #FFFFFF;
border-radius: 15px;
}
/*# sourceMappingURL=radio.css.map */
<div class="radio-btn">
<input type="radio" name="insertType" id="insertByUrl" value="url" checked>
<label for="insertByUrl" class="btn-field">
<div class="circle"></div>
</label>
</div>
<div class="radio-btn">
<input type="radio" name="insertType" id="insertByFile" value="file">
<label for="insertByFile" class="btn-field">
<div class="circle"></div>
</label>
</div>
Как сделать так, чтобы кружок тоже двигался при переключении?
Ответы (2 шт):
Автор решения: eccs0103
→ Ссылка
Уточнение
Когда-то давно делал такой переключатель, так как часто понадобилось в проектах. Теперь из архивов достаю и они пыльные очень. Прошу строго не судить.
Решение
body {
background-color: rgb(30, 30, 30);
}
input[type="checkbox"]+label[role="checkbox"].toggle {
cursor: pointer;
aspect-ratio: 3;
width: 30px;
display: flex;
border-radius: 50vmin;
padding: 2px;
background-color: rgb(255, 255, 255);
}
input[type="checkbox"]+label[role="checkbox"].toggle>span.knob {
aspect-ratio: 1;
height: 100%;
transform: scale(2);
border-radius: inherit;
margin-left: 0;
margin-right: auto;
background-color: rgb(200, 200, 200);
}
input[type="checkbox"]:checked+label[role="checkbox"] {
background-color: hsl(285, 80%, 40%);
}
input[type="checkbox"]:checked+label[role="checkbox"].toggle>span.knob {
margin-left: auto;
margin-right: 0;
}
input[type="checkbox"]:disabled+label[role="checkbox"] {
filter: opacity(0.5);
}
<input id="any-id" type="checkbox" hidden checked />
<label for="any-id" role="checkbox" class="toggle layer">
<span class="knob"></span>
</label>
<br />
<input id="any-other-id" type="checkbox" hidden disabled />
<label for="any-other-id" role="checkbox" class="toggle layer">
<span class="knob"></span>
</label>
Автор решения: Andrey Semykin
→ Ссылка
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background: black;
}
.radio-btn {
max-width: 40px;
min-height: 16px;
margin-top: 15px;
margin-left: 15px;
}
.radio-btn input {
display: none;
}
.radio-btn input:checked + label {
background: #D012FF;
box-shadow: 0 -18px 20px -12px #0B9090 inset;
}
.radio-btn .btn-field {
transition: all 300ms;
background: #D9D9D9;
max-width: 40px;
min-height: 16px;
border-radius: 5px;
display: grid;
position: relative;
}
.radio-btn .btn-field .circle {
position: absolute;
top: -3px;
left: -2.42px;
width: 22.42px;
height: 22.98px;
background: linear-gradient(180deg, #A00BC5 0%, #1B5454 100%);
border: 3px solid #FFFFFF;
border-radius: 15px;
}
.radio-btn .btn-field .circle {
position: absolute;
top: -3px;
left: -2.42px;
width: 22.42px;
height: 22.98px;
background: linear-gradient(180deg, #A00BC5 0%, #1B5454 100%);
border: 3px solid #FFFFFF;
border-radius: 15px;
}
.radio-btn input:checked + .btn-field > .circle{
transform: translateX(20px);
}
<div class="radio-btn">
<input type="radio" name="insertType" id="insertByUrl" value="url" checked>
<label for="insertByUrl" class="btn-field">
<div class="circle"></div>
</label>
</div>
<div class="radio-btn">
<input type="radio" name="insertType" id="insertByFile" value="file">
<label for="insertByFile" class="btn-field">
<div class="circle"></div>
</label>
</div>
