Horizontal alignment with CSS
5 answers
There are two problems here.
- To center a div containing a paragraph.
- To center the paragraphs that go into the div.
To center the DIV, here's the code using the inline style:
<div style="margin: 0 auto" class="one">
<p>Test<p>
</div>
The above centers the entire DIV, but DOES NOT align the text to the center. Again, the div will only be centered if the class "one" has the specified width. Otherwise, it does not affect. You can also include field style information inside a class named "one."
, , DIV , :
<div style="text-align: center" class="one">
<p>Test<p>
</div>
, <p>.
+4