我以为我永远不必问这样的问题。但现在开始了。
<!doctype html>
<head></head>
<body>
<style type="text/css">
.center_mobile { text-align: center; background: #ccc; width: 300px; }
</style>
<div class="center_mobile">Dumb!</div>
</body>
</html>
为什么 div 上的文本没有按照 text-align 的指示在其容器上居中?
但是这会使文本居中:
<div style="text-align: center;">Dumb!</div>
我不想内联输入样式。如何解决这个“问题”?
代码可以在这里运行:http://www.practiceboard.com/?936248
谢谢。
更新和“修复”
删除该样式上的空白可以解决问题。
.center_mobile {text-align:center; background: #ccc; width: 300px; }
最佳答案
在您的 css block 中删除 text-align
规则之前的空格。
关于html - 文本对齐 : center won't work unless inline css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23778330/