首页 > 解决方案 > 页面缩放时元素 CSS 样式的问题

问题描述

我有一个简单的自定义切换开关 CSS ,目前我的问题是当我将页面(例如使用 Chrome )缩放到 70-80% 时,滑块向左移动了一点,你可以看到滑块左侧的红色背景拇指出现。附上屏幕截图

如何解决这个问题?我希望我的拇指/滑块位置在所有页面的所有缩放级别都保持不变。

例如,如果您使用 chrome(在 25 - 33% 之间缩放)也会发生同样的问题,您会注意到相同的样式问题

页面缩放 70-80% 时出现问题的屏幕截图

.switch-input {
 display: none;
}
.switch-label {
  position: relative;
  display: inline-block;
  cursor: pointer;
  font-weight: 500;
  text-align: left;
}
.switch-label:before, .switch-label:after {
  content: "";
  position: absolute;
  margin: 0;
  outline: 0;
  top: 50%;
  -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: red;
  border-radius: 10px;
}
.switch-label:after {
  left: 0;
  width: 20px;
  height: 20px;
  background-color: #FAFAFA;
  border-radius: 50%;
}
<div>
    Input: <input type="checkbox" id="id-name--1" name="set-name" class="switch-input"  />
        <label for="id-name--1"  class="switch-label"/>
</div>

标签: csssassstyles

解决方案


推荐阅读