Answer the question
In order to leave comments, you need to log in
How to set margin: 0 auto; if the parent element's position is set to absolute?
Hello, I have a block:
<div class="mainscreen__content">
<div class="container">
</div>
</div>
.mainscreen__content {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Answer the question
In order to leave comments, you need to log in
I would recommend removing position: absolute;
and align mainscreen__content with display:flex; align-items: center; (this should be written to the parent)
and then margin: 0 auto should work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question