Reputation: 33395
I need to set width
or max-width
in order for margin:auto
to work, right? Like in this jsFiddle.
Trouble is, the paragraph width is equal to max-width
and so the block of text is not properly centered.
How can I make the width of the paragraph contract to be only just big enough to contain the text, expanding to max-width
as necessary?
No javascript and no fixed widths. Thanks.
Upvotes: 0
Views: 745
Reputation: 71918
I'm not sure, but maybe an inline-block
paragraph is what you're looking for:
<div>
<p>Lorem ipsum dolor sit amet</p>
</div>
div { text-align: center; }
p { display: inline-block; text-align: left; max-width: 40ex; }
Upvotes: 2
Reputation: 10619
Do you want to center the text in p, why not use text-align:center;
property
Upvotes: 0
Reputation: 15
did you try to set a max-width / or a width in percentage ?
It would be like that :
div { width: 100%; background: red; } p { margin: 0 auto 0 auto; background: blue; max-width: 90%; }
you can try it on your jsFiddle.
Hope this will help you.
Upvotes: 0