切换按钮边框 space
Toggle button border space
如屏幕截图所示,边框和背景之间存在一些 space。它连接到 border-radius 和 overflow: hidden。
如果我在所有地方删除边框半径,它就可以正常工作。我想删除那个间距。我在 Chrome 和 Firefox 上测试过它。
Screen Toggler 边框瑕疵
Screen Toggler 边框伪像突出显示
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: transparent;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #4680fe;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>
</div>
更改 background-color of .toggle__track #4680fe 和 .toggle__handler #ffffff
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: #4680fe;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #ffffff;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>
</div>
为.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track
添加background-color
应该可以解决差距问题,尽可能不改变你的效果。
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
background-color: #4680fe;
transition: background-color 250ms ease;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: transparent;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #4680fe;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>
如屏幕截图所示,边框和背景之间存在一些 space。它连接到 border-radius 和 overflow: hidden。 如果我在所有地方删除边框半径,它就可以正常工作。我想删除那个间距。我在 Chrome 和 Firefox 上测试过它。
Screen Toggler 边框瑕疵
Screen Toggler 边框伪像突出显示
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: transparent;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #4680fe;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>
</div>
更改 background-color of .toggle__track #4680fe 和 .toggle__handler #ffffff
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: #4680fe;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #ffffff;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>
</div>
为.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track
添加background-color
应该可以解决差距问题,尽可能不改变你的效果。
.toggle {
display: inline-block;
position: relative;
overflow: visible;
height: auto;
width: 100%;
cursor: pointer;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track {
border-color: #4680fe;
background-color: #4680fe;
transition: background-color 250ms ease;
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__circle {
transform: translate(0, 0);
}
.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track .toggle__handler {
transition: left 250ms ease-in-out 50ms, right 250ms ease-in-out, background-color 250ms ease-in-out;
left: 24px;
right: 0;
background-color: white;
}
.input--hidden {
position: absolute;
left: 0px;
cursor: inherit;
pointer-events: all;
opacity: 0;
width: 100%;
height: 100%;
z-index: 1;
padding: 0px;
margin: 0px;
}
.input__row {
position: relative;
display: flex;
width: 100%;
height: 100%;
}
.toggle__container {
display: flex;
flex-shrink: 0;
position: relative;
box-sizing: border-box;
}
.toggle__track {
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
box-sizing: border-box;
border-radius: 12px;
transition: border 250ms 0ms linear;
background-color: transparent;
box-shadow: 0 1px 1px rgba(70, 128, 254, 0.1);
border: 2px solid rgba(70, 128, 254, 0.4);
}
.toggle__circle {
display: block;
position: absolute;
top: -2px;
left: -2px;
transform: translate(-100%, 0);
transition: transform 250ms 0ms cubic-bezier(0.165, 0.84, 0.44, 1);
border-radius: 12px;
background-color: #4680fe;
}
.toggle__container,
.toggle__circle {
width: 48px;
height: 24px;
}
.toggle__handler {
position: absolute;
top: 0;
left: 0;
height: 16px;
margin: 2px;
right: 24px;
transition: left 250ms ease-in-out, right 250ms ease-in-out 50ms, background-color 250ms ease-in-out;
border-radius: 8px;
background-color: #4680fe;
box-shadow: 0 3px 6px rgba(70, 128, 254, 0.5);
}
<div class="toggle toggle--checked">
<input type="checkbox" class="input--hidden" checked>
<div class="input__row">
<div class="toggle__container">
<div class="toggle__track">
<span class="toggle__circle"></span>
<div class="toggle__handler"></div>
</div>
</div>
</div>
</div>