水平中心&lt; P&GT;一个div内,同时保持文本左对齐 [英] Horizontally center <p> within a div while keeping the text left-aligned
问题描述
我有多个的div一个固定的宽度包含&LT; P&GT;
标签包含文本的各种长度
I have multiple divs with a fixed width containing <p>
tags which contain various lengths of text.
我想这段文字保持左对齐,但如果文本不会占用尽可能多的空间的DIV宽度,我想集中对齐这个文本。
I want this text to remain left-aligned but if the text does not take up as much space as the div width, I would like to align this text centrally.
我认为实现这一目标的最佳途径是将水平居中的&LT; P&GT;
,同时保持左对齐的文字,但我不知道该div中如何做到这一点。
I assume the best way of achieving this would be to horizontally center the <p>
within the div while keeping the text left-aligned but I'm not sure how to do this.
我已经尝试设置保证金:0汽车;
但&LT; P&GT;
总是调整为宽度股利(除非我告诉它,否则,但我不想这样做,因为如果文字不是我不想早早打破它的股利......再运行)
I have tried setting margin:0 auto;
but the <p>
always resizes to the width of the div (unless I tell it otherwise, but I don't want to do this because if the text runs for longer than the div I don't want to break it early...)
我已经设置了的jsfiddle这里证明: http://jsfiddle.net/VDhUa/
I've set up a JSfiddle here to demonstrate: http://jsfiddle.net/VDhUa/
(基本上在这个例子中,我想Lorem存有...的东西,而无需使用的text-align集中对齐:中心;
)
(Basically in this example I would like to "Lorem ipsum..." stuff to be centrally aligned without using text-align:center;
)
任何帮助将大大AP preciated。
Any Help would be greatly appreciated.
感谢您!
推荐答案
设置你的外格到文本对齐:中心;
和你内心的P公司为显示:inline-block的;
Set your outer div to text-align: center;
and your inner p's to display: inline-block;
小提琴: http://jsfiddle.net/ZL4GM/
这篇关于水平中心&lt; P&GT;一个div内,同时保持文本左对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!