Martyn99
05-25-2010, 11:11 PM
I am writing a CMS. I need a text block element to align in the centre with the text inside aligned left. Because it is a CMS there is no way of knowing how much content is in the element so I cannot set a width.
If there is only one word it needs to be in the middle and if there are paragraphs they need to have the text aligned left and expand to the width of the containing div.
The element needs to collapse on the content. I can do it with tables but can't figure out how to do it without tables. Although I'm not sure why tables are so bad but they seem to be frowned upon and I'd love to conform. Is it possible?
This does exactly what I want:
<table style="margin: 0 auto"><tr><td>sldmnfkj</td></tr></table>
or
<table style="margin: 0 auto">
<tr><td>
kjh kjhkjh<br>
lsfkdj<br>
sfldkj sdlfkj lsdfkj sldfkj<br>
</td></tr>
</table>
I'm using PHP's nl2br() for the line breaks.
If there is only one word it needs to be in the middle and if there are paragraphs they need to have the text aligned left and expand to the width of the containing div.
The element needs to collapse on the content. I can do it with tables but can't figure out how to do it without tables. Although I'm not sure why tables are so bad but they seem to be frowned upon and I'd love to conform. Is it possible?
This does exactly what I want:
<table style="margin: 0 auto"><tr><td>sldmnfkj</td></tr></table>
or
<table style="margin: 0 auto">
<tr><td>
kjh kjhkjh<br>
lsfkdj<br>
sfldkj sdlfkj lsdfkj sldfkj<br>
</td></tr>
</table>
I'm using PHP's nl2br() for the line breaks.