I have another one that I used to use before I learned flexbox and grid...
<!-- HTML --> <p class="p">This is a paragraph</p>
/* CSS */ .p { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
Mostly I used to do this when the page I build will fit the user's device screen without any scrollbars. (As in height: 100vh and width: 100%;)
height: 100vh
width: 100%;
Thanks it just helped me to center a div. 😃
Niiice. You're welcome Olga
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have another one that I used to use before I learned flexbox and grid...
<!-- HTML -->
<p class="p">This is a paragraph</p>
/* CSS */
.p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Mostly I used to do this when the page I build will fit the user's device screen without any scrollbars. (As in
height: 100vh
andwidth: 100%;
)Thanks it just helped me to center a div. 😃
Niiice. You're welcome Olga