[CSS] How to center text vertically
Author | Message |
---|---|
Ordo | # Posted two hours ago |
Hello. | |
Ads | |
Rel0ad | # Posted one hour ago |
![]() |
Sigh... https://www.siteraw.com/html-css/how-to-create-a-website/flexbox-layouts |
Phoenix | # Posted one hour ago |
![]() |
There is more than one way to align an element on the vertical axis. Method 1 - FlexboxAs Rel0ad said, it is covered in depths in the SiteRaw tutorial. .container { Method 2 - Transform & translateAlternatively, you could also use this method which will work on most browsers. .container { Method 3 - Table cellIn some cases, you will need to ensure that the html / body element's height is set to 100%. .parent { Method 4 - Absolute positioningThis approach assumes that the text has a known height (20 pixels in the demo) so I only recommend it as a last resort. We use a negative margin to vertically center our content. .container > p { Method 5 - Line heightThis is the least flexible method, for educational purposes only. .container { |
Ordo | # Posted 7 minutes ago |
Thanks, it works as intended. |
Post a reply
Please be kind and courteous in your replies. Don't roast others for no reason.