+ 2

Hiw to align a text to center along with changing the width of the background color

h1{ Color: crimson; Text-align:center; Background-color:red; Width:50%}

9th Mar 2020, 6:17 AM
JANARTHANAN G
JANARTHANAN G - avatar
13 Answers
+ 2
its still in the center https://code.sololearn.com/WhfAotbvqve0/?ref=app maybe your problem is h1 is not in the center of its parent. not the text inside the h1
9th Mar 2020, 8:12 AM
Taste
Taste - avatar
+ 1
I did but it is not working when I use the width option
9th Mar 2020, 8:00 AM
JANARTHANAN G
JANARTHANAN G - avatar
+ 1
Could you please tell me how to fix this
9th Mar 2020, 1:56 PM
JANARTHANAN G
JANARTHANAN G - avatar
+ 1
Yes
9th Mar 2020, 3:32 PM
JANARTHANAN G
JANARTHANAN G - avatar
10th Mar 2020, 1:35 AM
JANARTHANAN G
JANARTHANAN G - avatar
+ 1
This is it
10th Mar 2020, 1:35 AM
JANARTHANAN G
JANARTHANAN G - avatar
+ 1
The problem is with h1
10th Mar 2020, 1:45 AM
JANARTHANAN G
JANARTHANAN G - avatar
+ 1
So you have added an ID for head and fixed the problem
10th Mar 2020, 6:10 AM
JANARTHANAN G
JANARTHANAN G - avatar
0
use text-align: center in the text container
9th Mar 2020, 6:44 AM
Taste
Taste - avatar
0
you have the code ?
9th Mar 2020, 2:38 PM
Taste
Taste - avatar
0
can i see it ?
9th Mar 2020, 3:33 PM
Taste
Taste - avatar
0
yes, so h1 is centered relative to its parent
10th Mar 2020, 6:13 AM
Taste
Taste - avatar