- 1
How to centre text with background
5 Answers
0
Got the correct code
https://code.sololearn.com/WCdfdwc9igQ7/?ref=app
+ 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;
}
+ 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!
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.
0
Sanket Ichharam Barde good job!