Why the Text-align: center; wont work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the Text-align: center; wont work?

I am just confused I tried everything and nothing happened.

29th Nov 2017, 2:25 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
17 Answers
+ 5
I don't have Opera, so I'll post this for you to try first, and if not, I'll download Opera so I can see it first-hand. Change .buttonContainer to: .buttonContainer { width: 100%; text-align: center; margin: 0 auto; }
29th Nov 2017, 2:40 PM
AgentSmith
+ 3
https://code.sololearn.com/W43dH3oUgeXl/#html .buttonContainer { text-align: center; } <div class="buttonContainer"> <button class="button" onclick="alert('Thanks For supporting')" align="center">Yes</button> <button class="button" onclick="alert('Contact us')" align="center">No</button> </div>
29th Nov 2017, 2:34 PM
AgentSmith
+ 2
I just remembered all the things I hate about web development. :) Anyways, it could be many reasons, because many things affect the alignment of it. You may need to nest your element, maybe fix what's set on its parent, try margin: 0 auto;, try text-align: center;, etc.... Honestly, without seeing your code, it's hard to be specific on it. Post up your code and we can let you know for certain what's causing it.
29th Nov 2017, 2:29 PM
AgentSmith
+ 2
Ok thanks for helping I really appreciate your answers
29th Nov 2017, 2:45 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
29th Nov 2017, 2:26 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
+ 1
Yup, I'm sure; at least with Chrome browser. Most of the time you just need to nest the elements you want centered and then align the container. Sometimes "margin: 0 auto;" is really useful for the trickier elements that won't center. Really just depends, not everything acts in the same way that you'd expect. What browser are you using Yaman? It works flawlessly on my end, but again, I'm using Chrome. I'll test it in other browsers and adjust the code to make sure it works in the browser you prefer. This is the part of web development that I hated the most; y u no force standards?
29th Nov 2017, 2:38 PM
AgentSmith
+ 1
It worked perfectly
29th Nov 2017, 2:42 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
+ 1
it worked
29th Nov 2017, 2:42 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
+ 1
@Yaman Okay, perfect! If you have a piece of paper or something, write all of those things down for future reference. 99% of the time, one of those things I mentioned fixes the problem with centering.
29th Nov 2017, 2:44 PM
AgentSmith
0
Wait a min
29th Nov 2017, 2:26 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
The last 2 buttons
29th Nov 2017, 2:27 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
I post it already
29th Nov 2017, 2:30 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
are you sure?
29th Nov 2017, 2:34 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
It isnt working
29th Nov 2017, 2:36 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
I am using Opera
29th Nov 2017, 2:38 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
Ok I'll try
29th Nov 2017, 2:41 PM
Yaman Bashar Abu Laban
Yaman Bashar Abu Laban - avatar
0
You're welcome.
29th Nov 2017, 2:53 PM
AgentSmith