1

I have a simple toggle switch taken from W3school.

The problem is when I zoom in the page using Chrome/Firefox to 33% or 60%, I notice a child white square button inside the parent is not rendered correctly. Screenshot attached.

I have copied the same toggle switch 3 times, I expect to have the same style on page zooming at least with all 3 toggle switches, but sometimes 1 of the 3 changes differently to the other ones. I can't find a solution to this problem and it took too much time for me to find a solution.

The issue of the 1st toggle switch is not the same to others on page zoom-in 33%

enter image description here

100% page

Default page 100%

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  display: none;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked+.slider {
  background-color: #2196F3;
}

input:focus+.slider {
  box-shadow: 0 0 1px #2196F3;
}

input:checked+.slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}


/* Rounded sliders */

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">

</head>

<body>

  <h2>Toggle Switch</h2>

  <label class="switch">
      <input type="checkbox">
      <span class="slider"></span>
    </label>

  <label class="switch">
      <input type="checkbox" checked>
      <span class="slider"></span>
    </label><br><br>

  <label class="switch">
      <input type="checkbox">
      <span class="slider"></span>
    </label>

  <label class="switch">
      <input type="checkbox" checked>
      <span class="slider"></span>
    </label><br><br>

  <label class="switch">
      <input type="checkbox">
      <span class="slider"></span>
    </label>

  <label class="switch">
      <input type="checkbox" checked>
      <span class="slider"></span>
    </label><br><br>

  </label>

</body>

</html>
chintuyadavsara
  • 1,509
  • 1
  • 12
  • 23
  • 2
    I think ithis could be a browser rendering issue. The 4px "padding" will be 1.32px when viewed zoomed out to 33%. See https://stackoverflow.com/questions/34676263/sub-pixels-calculated-and-rendered-differently-among-browsers for subpixel rendering. – theyve Oct 09 '18 at 13:02
  • That's exactly my issue, but still his answer didn't fix my problem, Also this rendering issue happen on cross browsers. tested on Chrome/Edge/Firefox – user10478430 Oct 09 '18 at 13:37

0 Answers0