Considering code below:
.switch {
display: flex;
appearance: none;
border: none;
background-color: white;
align-items: center;
}
.switch::before {
height: 45px;
border-radius: 200px;
background-color: blue;
display: flex;
align-items: center;
padding: 0px 50px 0px 2px;
content: "•";
color: white;
font-size: 100px;
}
<button class="switch" type="submit">
Can edit users
</button>
It might not be obvious, but the toggle (white dot) is not vertically-aligned inside its container (blue box). It seems link to baseline
; but I dunno how to fix it.
It there a way to make this toggle perfectly vertical-aligned without creating another div
?
Or, is there another way to make it works without creating another div
?
Thanks.
2
Answers
Since you use
content: "•";
, the position of the dot will depend on the font you are using. Therefore, I offer the following solution:Build it with a
radial-gradient
and you can easily control the position/size like you want: