将Div左对齐文本居中[关闭](Center a Div Left Justified Text [closed])
我有一些标题文本,大字体,两到四行。 它左对齐,但我也希望它水平和垂直居中。 问题是它在div的末尾包裹并留下一些空白区域(设置为600px的宽度)。 所以我希望它水平居中,不是基于600px,而是基于最长线的宽度。 有没有办法让div宽度成为最长文本行的长度?
I have some header text that is large font, two to four lines. It is left justified, but I also want it centered horizontally and vertically. The problem is that it wraps and leaves some blank space at the end of the div (which is set at a width of 600px). So I want it to be centered horizontally, based not on 600px, but the width of the longest line. Is there a way to make the div width the length of the longest line of text?
最满意答案
我想这就是你想要的?
#container { background:gold; width:600px; font-size:2em; display:inline-block; } #title { width:400px; margin-right:100px; margin-left:100px; margin-top:50px; margin-bottom:50px; font-weight:600; }<html> <head></head> <body> <div id=container> <p id=title>Here it comes a long sentence that takes about 2 lines.</p> </div> </body> </html>I guess that's what you want?
#container { background:gold; width:600px; font-size:2em; display:inline-block; } #title { width:400px; margin-right:100px; margin-left:100px; margin-top:50px; margin-bottom:50px; font-weight:600; }<html> <head></head> <body> <div id=container> <p id=title>Here it comes a long sentence that takes about 2 lines.</p> </div> </body> </html>
更多推荐
发布评论