Test

β–ΌThis is a ...">

Horizontal alignment with CSS

I have the following code:

<div class="one">
   <p>Test<p><span style="color: Green">β–Ό</span>
</div>

This is a very simple question, I think, but I do not know CSS. How to make a paragraph look horizontal in the center?

+3
source share
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

.One{text-align:center;}

.One p{margin: 0 auto;}
+1

CSS. margin:auto

0

<head>

    <style type="text/css">
        .one p {text-align:center;}
    </style>

div, , , div.

    <style type="text/css">
        .one p {margin:0 auto; width:300px;} /*Change the width to what you need to*/
    </style>

http://www.sohtanaka.com/web-design/vertical-alignment-css/

0

All Articles