divriots / code.to.design

The only API for HTML to Figma
1 stars 0 forks source link

Positioning issues #13

Closed adamgiebl closed 11 months ago

adamgiebl commented 11 months ago

Describe the bug image

To Reproduce

<div class="main">
<label class="switch">
  <input type="radio" name="value-radio">
  <div class="button">
    <div class="light"></div>
    <div class="dots"></div>
  </div>
</label>
<label class="switch1">
  <input type="radio" checked="" name="value-radio">
  <div class="button">
    <div class="light"></div>
    <div class="dots"></div>
  </div>
</label>
<label class="switch2">
  <input type="radio" name="value-radio">
  <div class="button">
    <div class="light"></div>
    <div class="dots"></div>
  </div>
</label>
<div class="back"></div>
</div>
/*Design Inspired by @ykadosh on Codepen*/

.back {
  position: absolute;
  width: 16.6em;
  height: 6.5em;
  margin-top: -0.8em;
  margin-left: -0.77em;
  border-radius: 70px;
  box-shadow: rgba(0, 0, 0, 0.4) 0px 2px 2px, rgba(0, 0, 0, 0.3) 0px 7px 13px -3px, rgba(0, 0, 0, 0.2) 0px -1px 0px inset;
  background-color: #171717;
  z-index: -1;
}

.main {
  display: flex;
}

.switch {
  display: block;
  position: relative;
  background-color: black;
  width: 70px;
  height: 70px;
  box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2), 0 0 1px 2px black, inset 0 2px 2px -2px white, inset 0 0 2px 5px #47434c, inset 0 0 2px 22px black;
  border-radius: 50%;
  padding: 20px;
  margin: 5px;
}

.switch input {
  display: none;
}

.switch input:checked + .button .light {
  animation: flicker 0.2s infinite 0.3s;
}

.switch input:checked + .button .shine {
  opacity: 1;
}

.switch input:checked + .button .shadow {
  opacity: 0;
}

.switch .button {
  transition: all 0.3s cubic-bezier(1, 0, 1, 1);
  background-color: #9b0621;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  position: relative;
  left: -0.75em;
  top: -0.75em;
  cursor: pointer;
}

.switch .light {
  opacity: 0;
  animation: light-off 1s;
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(#ffc97e, #ff1818 40%, transparent 70%);
}

.switch .dots {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(transparent 30%, rgba(101, 0, 0, 0.7) 70%);
  background-size: 10px 10px;
  border-radius: 50%;
}

@keyframes flicker {
  0% {
    opacity: 1;
  }

  80% {
    opacity: 0.8;
  }

  100% {
    opacity: 1;
  }
}

@keyframes light-off {
  0% {
    opacity: 1;
  }

  80% {
    opacity: 0;
  }
}

.switch1 {
  display: block;
  position: relative;
  background-color: black;
  width: 70px;
  height: 70px;
  box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2), 0 0 1px 2px black, inset 0 2px 2px -2px white, inset 0 0 2px 5px #47434c, inset 0 0 2px 22px black;
  border-radius: 50%;
  padding: 20px;
  margin: 5px;
}

.switch1 input {
  display: none;
}

.switch1 input:checked + .button .light {
  animation: flicker 0.2s infinite 0.3s;
}

.switch1 input:checked + .button .shine {
  opacity: 1;
}

.switch1 input:checked + .button .shadow {
  opacity: 0;
}

.switch1 .button {
  transition: all 0.3s cubic-bezier(1, 0, 1, 1);
  background-color: #949207;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  position: relative;
  left: -0.75em;
  top: -0.785em;
  cursor: pointer;
}

.switch1 .light {
  opacity: 0;
  animation: light-off 1s;
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(#f6ff7e, #eeff00 40%, transparent 70%);
}

.switch1 .dots {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(transparent 30%, rgba(91, 101, 0, 0.7) 70%);
  background-size: 10px 10px;
  border-radius: 50%;
}

.switch2 {
  display: block;
  position: relative;
  background-color: black;
  width: 70px;
  height: 70px;
  box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2), 0 0 1px 2px black, inset 0 2px 2px -2px white, inset 0 0 2px 5px #47434c, inset 0 0 2px 22px black;
  border-radius: 50%;
  padding: 20px;
  margin: 5px;
}

.switch2 input {
  display: none;
}

.switch2 input:checked + .button .light {
  animation: flicker 0.2s infinite 0.3s;
}

.switch2 input:checked + .button .shine {
  opacity: 1;
}

.switch2 input:checked + .button .shadow {
  opacity: 0;
}

.switch2 .button {
  transition: all 0.3s cubic-bezier(1, 0, 1, 1);
  background-color: #2f9407;
  width: 55px;
  height: 55px;
  border-radius: 50%;
  position: relative;
  left: -0.75em;
  top: -0.79em;
  cursor: pointer;
}

.switch2 .light {
  opacity: 0;
  animation: light-off 1s;
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(#f6ff7e, #00ff00 40%, transparent 70%);
}

.switch2 .dots {
  position: absolute;
  width: 100%;
  height: 100%;
  background-image: radial-gradient(transparent 30%, rgba(0, 101, 13, 0.7) 70%);
  background-size: 10px 10px;
  border-radius: 50%;
}
gluck commented 11 months ago

Hi @adamgiebl , for this component to render properly, it seems it needs both:

* {
  box-sizing: border-box;
}

(which you set on your site, we don't)

And also a root font-size of 16px (as it mixes px & em positioning) <- this one's ok as it's the default.

If you add the box-sizing to your CSS, the positioning is OK (notice the tile gradient is not though, but that's another issue we already talked about): image

adamgiebl commented 11 months ago

Oh I see, did you ever think about setting certain defaults for a more consistent behavior? I believe there are differences between different browsers as well, that's why a lot of websites choose to include CSS resets.

That being said, I think there are pros and cons with both ways.

gluck commented 11 months ago

Didn't really think about it, because it sounds pretty trivial for a user to inject the reset CSS if they want one (whereas it'd be pretty difficult to undo a reset).