Webkit 浏览器上的奇怪问题,标签子项上有过渡
Strange issue on webkit browsers with transition on label childs
我在 Chrome 和 Opera 上遇到了这个奇怪的问题,但在 Firefox 上没有。我有一个带有自定义样式标签的复选框输入。标签内部有两个元素,上面有过渡。
片段:
body {
background-color: #2F3136;
text-align: center;
font-family: "Open Sans", sans-serif;
color: white;
font-weight: 400;
}
.main {
position: relative;
margin-top: 25px;
margin-left: 25px;
}
.switch-input {
display: none;
}
.switch-label {
position: absolute;
display: inline-block;
cursor: pointer;
font-weight: 500;
padding: 10px 0 10px 36px;
}
.switch-label.right {
top: 20%;
transform: translateY(-20%);
left: auto;
right: 50px;
}
.switch-label.center {
left: 50%;
transform: translateX(-50%);
}
.switch-label .before, .switch-label .after {
content: "";
position: absolute;
margin: 0;
outline: 0;
-ms-transform: translate(0, -50%);
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.switch-label .before {
left: 1px;
width: 34px;
height: 14px;
background-color: #9E9E9E;
border-radius: 8px;
}
.switch-label .after {
left: 0;
width: 20px;
height: 20px;
background-color: #FAFAFA;
border-radius: 50%;
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.14), 0 2px 2px 0 rgba(0, 0, 0, 0.098), 0 1px 5px 0 rgba(0, 0, 0, 0.084);
}
.switch-input:checked + .switch-label .before {
background-color: #A5D6A7;
}
.switch-input:checked + .switch-label .after {
background-color: #4CAF50;
-ms-transform: translate(80%, -50%);
-webkit-transform: translate(80%, -50%);
transform: translate(80%, -50%);
}
p {
margin-left: 0px;
text-align: center;
margin-bottom: 0px;
font-size: small;
}
.setting {
position: absolute;
width: fit-content;
top: 0;
height: 50px;
}
.setting.right {
margin-left: 150px;
}
<html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600&display=swap" rel="stylesheet">
</head>
<body>
<div class="main">
<div class="setting">
<p>before the label</p>
<input type="checkbox" id="enabled" class="switch-input" checked>
<label for="enabled" class="switch-label center">
<div class="before"></div>
<div class="after"></div>
</label>
</div>
<div class="setting right">
<p>after the label</p>
</div>
</div>
</body>
</html>
似乎每次我更改复选框状态并开始播放过渡时,标签元素之后的所有文本都会更改其权重或其他内容。我试过 css 看看是什么原因造成的,但我无法得出任何结论。
这里有一个视频,以防你遇到这种情况。看标签后文字的变化:https://imgur.com/a/1oLTKHa
试试这个 xD
.setting.right {
margin-left: 150px;
z-index: -1; //
}
我在 Chrome 和 Opera 上遇到了这个奇怪的问题,但在 Firefox 上没有。我有一个带有自定义样式标签的复选框输入。标签内部有两个元素,上面有过渡。 片段:
body {
background-color: #2F3136;
text-align: center;
font-family: "Open Sans", sans-serif;
color: white;
font-weight: 400;
}
.main {
position: relative;
margin-top: 25px;
margin-left: 25px;
}
.switch-input {
display: none;
}
.switch-label {
position: absolute;
display: inline-block;
cursor: pointer;
font-weight: 500;
padding: 10px 0 10px 36px;
}
.switch-label.right {
top: 20%;
transform: translateY(-20%);
left: auto;
right: 50px;
}
.switch-label.center {
left: 50%;
transform: translateX(-50%);
}
.switch-label .before, .switch-label .after {
content: "";
position: absolute;
margin: 0;
outline: 0;
-ms-transform: translate(0, -50%);
-webkit-transform: translate(0, -50%);
transform: translate(0, -50%);
-webkit-transition: all 0.3s ease;
transition: all 0.3s ease;
}
.switch-label .before {
left: 1px;
width: 34px;
height: 14px;
background-color: #9E9E9E;
border-radius: 8px;
}
.switch-label .after {
left: 0;
width: 20px;
height: 20px;
background-color: #FAFAFA;
border-radius: 50%;
box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.14), 0 2px 2px 0 rgba(0, 0, 0, 0.098), 0 1px 5px 0 rgba(0, 0, 0, 0.084);
}
.switch-input:checked + .switch-label .before {
background-color: #A5D6A7;
}
.switch-input:checked + .switch-label .after {
background-color: #4CAF50;
-ms-transform: translate(80%, -50%);
-webkit-transform: translate(80%, -50%);
transform: translate(80%, -50%);
}
p {
margin-left: 0px;
text-align: center;
margin-bottom: 0px;
font-size: small;
}
.setting {
position: absolute;
width: fit-content;
top: 0;
height: 50px;
}
.setting.right {
margin-left: 150px;
}
<html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;600&display=swap" rel="stylesheet">
</head>
<body>
<div class="main">
<div class="setting">
<p>before the label</p>
<input type="checkbox" id="enabled" class="switch-input" checked>
<label for="enabled" class="switch-label center">
<div class="before"></div>
<div class="after"></div>
</label>
</div>
<div class="setting right">
<p>after the label</p>
</div>
</div>
</body>
</html>
似乎每次我更改复选框状态并开始播放过渡时,标签元素之后的所有文本都会更改其权重或其他内容。我试过 css 看看是什么原因造成的,但我无法得出任何结论。
这里有一个视频,以防你遇到这种情况。看标签后文字的变化:https://imgur.com/a/1oLTKHa
试试这个 xD
.setting.right {
margin-left: 150px;
z-index: -1; //
}