如屏幕截图所示,边框和背景之间有一定距离。它连接到边界半径并溢出:隐藏。 如果我在任何地方删除边界半径,都可以正常工作。我想删除该间距。我在Chrome和Firefox上进行了测试。
屏幕切换边框的伪像
突出显示屏幕切换器边框的伪像
.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>
答案 0 :(得分:1)
为background-color
添加.toggle input[type=checkbox]:checked + .input__row .toggle__container .toggle__track
应该能够解决差距问题,从而不会改变效果。
.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>
答案 1 :(得分:0)
更改.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>