Search code examples
cssalignmentcenter

How can I center the block of text without the next line being centered relative to the top line?


I need to center the text. I used text-align center but the next line gets centered. I need it to be aligned to the line on top.

<div class="box">
<div class="text">Some text.Some text.Some text.Some text.Some text.Some text.Some text.
    Some text.Some text.Some text.Some text.Some text.</div>
</div>

How can I center the block of text without the next line being centered relative to the top line?

http://jsfiddle.net/heQ9H/


Solution

  • One cheap way to do this is to wrap the text inside an element which you've already did, get the nearest width, where your text just ends perfect instead of wrapping to other line leaving a large space on the right, and than use margin: auto;

    Demo

    .text {
        width: 490px;
        margin: 0 auto;
    }