for parent block or body - text-align:center; for centerd block- display:inline-block;
<style>
body{text-align:center}
.center{display:inline-block;background:red}
</style>
<div class="center">
<p contenteditable="true">write text</p>
</div>
DEMO http://jsfiddle.net/RXP4F/
参考: http://stackoverflow.com/a/18524791/4484798
关于 inline-block 的用法, 请参考文章: 详解CSS display:inline-block的应用
本文转自: CSS: 居中一个宽度为auto的块元素 (width:auto;margin:auto) center an auto-width div
本文介绍了一种使用CSS实现块元素居中的方法,通过设置body的text-align为center及使用display:inline-block属性来达到效果,并提供了示例代码及在线演示链接。
310

被折叠的 条评论
为什么被折叠?



