L
L
Let_peace2020-08-26 21:07:42
css
Let_peace, 2020-08-26 21:07:42

Why doesn't a centered element get centered?

HTML:

<label class="label">
  <span class="label-span label-span-selected"></span>
</label>
<label class="label">
  <span class="label-span"></span>
</label>
<label class="label">
  <span class="label-span"></span>
</label>


CSS:

.label{
  margin: 0 3px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background-color: #fff;
  border-radius: 50%;
}
.label-span{
  display: block;
  width: 16px;
  height: 16px;
  background-color: #777;
  border-radius: 50%;
}
.label-span-selected{
  background-color: #333;
}


When I zoom in on the page (CRTL+), the label-span becomes crooked in the browser (at different scales): 100%

5f46a409c6de4912698426.png
125%

5f46a4186b426144706555.png
175%

5f46a4247e213355119508.png

It doesn't look like I would like, but I think I wrote everything correctly. How to avoid this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ankhena, 2020-08-26
@Let_peace

At 175% scale, the parent becomes 35px, the child 28px.
How would you like it to be drawn exactly in the center of the parent?
You can try to replace centering with flex with absolute with transform.
But it is better to get rid of span'a. Why 2 tags, if all this is solved by one tag. And just border
https://jsfiddle.net/uqfpbx1w/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question