简体   繁体   English

如何将div内部的div水平居中,而内部的div具有其文本内容的宽度?

[英]how to center div inside div horizontally and inner div have width of its text content?

Outer div have certain width. 外div有一定的宽度。 But inner div should have the width equal to its text content and inner div should be horizontally centered 但是,内部div的宽度应等于其文本内容,并且内部div应当水平居中

<div id="outer">
<div id="inner">
Hello....
</div>
</div>

set inner div as display:inline-block and parent text-align:center 将内部div设置为display:inline-block和parent text-align:center

 #outer { width: 200px; border: 1px solid red; text-align: center } #inner { display: inline-block; border: 1px solid green; } 
 <div id="outer"> <div id="inner"> Hello.... </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM