1

I have some text that I want simultaneously centered on the page and the text within the paragraph to be adjusted to the left? A little help?

this is what I've been trying

      <p align="center"><div align="left>text<br>more text</p></div>

obviously not working this just shifts everything left

Doug
  • 597
  • 2
  • 7
  • 22

2 Answers2

0

align="center" and align="left" are deprecated. Use CSS instead.

Here's one way to do it (assuming you want 2 nested elements, or see Brad's method for centering a single element): http://jsfiddle.net/EzNJQ/1/

<div id="outer">
    <p id="inner">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    </p>
</div>​

#outer{
    width: 300px;
    margin: 0 auto; /* centers */
}
#inner {
    text-align: left;   
}

More examples: http://www.w3.org/Style/Examples/007/center.en.html

Tim M.
  • 53,671
  • 14
  • 120
  • 163
0

What the troubling part (although IE is always different) is that in order for an item to be centered the horizontal margins need to be set to auto (allowing the browser to actually center the content). So, with that being said:

p.centered {
    margin: 0px auto;
    width: 300px;
    border: 1px solid #f0f;
}

<p class="centered">This is your paragraph</p>

The width is your call (and I've added a border for clarity) but just set the side margin to auto and the content will be left-aligned (unless otherwise specified by text-align).

Brad Christie
  • 100,477
  • 16
  • 156
  • 200