Answer the question
In order to leave comments, you need to log in
Why is there no simple center positioning?
The question has long occupied me. Why is there not one simple directive for positioning a block in the center (vertically and horizontally) (okay, let's say two)? The center location is what a person encounters immediately in the html layout. Why is it necessary to use all sorts of "recipes" with negative indents, flaxes and other garbage? Why is the world like this? What are the reasons?
Answer the question
In order to leave comments, you need to log in
like this no:
display:flex;
justify-content:center;
align-items:center;
So that life does not seem like a raspberry))
Now it already exists, so they wrote to you about flexes.
If you want to center an element with one line, give it margin: auto, or as mentioned above, the difference is that justify-content and align-items are on the parent, and margin auto is on the child.
In addition to all of the above, IT development is just wonderful in that previously written code can be used so many times. Write once any centering (at least light flex, hol add hardcore 10 lines) and use everywhere.
By and large, because html / css was originally invented for documents and vertical centering was not necessary.
And for horizontal there have always been a bunch of ways starting with the center tag
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question