How to centre text with background | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
17th Jun 2020, 1:04 PM
Sanket Ichharam Barde
Sanket Ichharam Barde - avatar
5 Answers
17th Jun 2020, 4:14 PM
Sanket Ichharam Barde
Sanket Ichharam Barde - avatar
+ 3
Put this in CSS page ------------------------------------ body{ padding-left:5px; } h1{ color:white; text-align:center ; } .middle { background:red; border-radius: 40px; width:100%; border-style:double ; border-color:pink; }
17th Jun 2020, 1:18 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 2
MuhammadⓂ️🥇🛡️✔️ that would work, but the box would then take the whole page and he set it to 60% before. I suggest using ----------------------------------------- margin-left: auto; margin-right: auto; ----------------------------------------- To center horizontally And to center horizontally and vertically, I would use ----------------------------------------- position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; ----------------------------------------- I have not yet tested this, so please correct me if I'm wrong. Happy coding!
17th Jun 2020, 1:35 PM
Ruben Uijtdewilligen
Ruben Uijtdewilligen - avatar
0
Thanks I tried both the codes but not getting desired effect MuhammadⓂ️🥇🛡️✔️ I tried code suggested by you but then background colour occupies entire width and what I want is to occupy only text area. Ruben 💞 thanks but with this code it's still left aligned without background colour. Thanks again.
17th Jun 2020, 3:55 PM
Sanket Ichharam Barde
Sanket Ichharam Barde - avatar
17th Jun 2020, 4:49 PM
Ruben Uijtdewilligen
Ruben Uijtdewilligen - avatar