+ 4

How do you center a text or object VERTICALLY using CSS/HTML?

Do you know of a quick simple solution? I have both paragraph and an image inside two separate div (container). How can I centralize the p and img VERTICALLY within the container such that it will stay in the middle even if on a wider screen. (Responsive)

25th Jul 2019, 1:14 AM
Keleos William
Keleos William - avatar
4 Respuestas
+ 3
In CSS : . container { width: 500px; height: 300px; display: flex; /* center horizontally */ justify-content: center; /* vertically */ align-items: center; }
25th Jul 2019, 2:27 PM
Djo Djo
Djo Djo - avatar
+ 1
Thanks Djo Djo . This lines saved me: display:flex; align-items:center; Appreciated!
25th Jul 2019, 3:46 PM
Keleos William
Keleos William - avatar
0
Go into your css. body { width: 500px; height: 300px; display: flex; justify-content: center; align-items: center; }
27th Jul 2019, 1:15 AM
P̷̖͒l̷͍̈ȕ̶̙t̴̤̐o̵̻̒ ̶̻̈́Ä̸̡́í̴̻ḓ̸̈́à̷̰n̷̩̈
P̷̖͒l̷͍̈ȕ̶̙t̴̤̐o̵̻̒ ̶̻̈́Ä̸̡́í̴̻ḓ̸̈́à̷̰n̷̩̈ - avatar
- 1
Jeez. Wish I'd known about 'display:flex;' 7 years ago. Could have saved myself some brain damage, writing unnecessary tables just to center content. Now I know. Thanks.
30th Jul 2019, 12:45 PM
Richard Bester
Richard Bester - avatar