0

I have a simple piece of html:

  <div style="width:60%;color:#000;text-align:center;">
    This is a test
  </div>

I want to center the text that is inside the div, but it is not working. I have tried other solutions in similar stack overflow questions but to no avail. I have tried using the use text-align in a paragraph element, but that does not work also. How can I get it to center horizontally?

It is presently aligning left.

user3648426
  • 227
  • 1
  • 4
  • 13

3 Answers3

2

Your code is working on my machine.

The way you have it written, the string will center itself within 60% of the div's available space. This will have an effect of looking slightly off-center, but technically centered within your div.

If you want it dead center in the middle of your page, change the width to 100%.

Sean
  • 427
  • 3
  • 9
-2

Try using:

 <center>
    your text here
 </center>

inside your div

Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
angel
  • 104
  • 12
-2

I just want to add that using <section> instead of also works for the specific purpose I need.

Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
user3648426
  • 227
  • 1
  • 4
  • 13