css - 使用 css 和 html 将 div 框居中,而不将框中的文本居中

标签 css forms html

我想将我在此处制作的 div 框居中,但我不想将框中的文本居中,而且我似乎找不到如何执行此操作。现在我所拥有的是:

.box {
        text-align: left;
        background-color:#3F48CC;
        color:white;
        font-weight:bold;
        margin:120px auto;
        height:150px;
        display: inline-block;
        width: 200px;
    }

<div class=box>
    Login
    <form method ="post" action="addMember.php">
      <label for="name">Username:</label>
      <input name="name"/>
      <label for="password">Password:</label>
      <input name="password"/>
        <p>
        <input name="submit" type="Submit" value="Register"/>
        <input name="reset" type="reset" value="Clear Form">
  </form>
 </div>

提前致谢!

最佳答案

删除 display: inline-block; & text-align:center

当您为 div 定义 width/height 时,

inline-block 不是必需的。

默认情况下,div 是一个 block 元素。

.box {       
        background-color:#3F48CC;
        color:white;
        font-weight:bold;
        margin:120px auto;
        height:150px;        
        width: 200px;
    }

DEMO

关于css - 使用 css 和 html 将 div 框居中,而不将框中的文本居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14275492/

相关文章:

html - 样式 CSS 因浏览器而异

javascript - 允许使用 Html <img src ="&lt;script&gt;Some javascript&lt;/script&gt;"> 吗?

html - html中的子菜单

css - 幻灯片动画在 Firefox 25.0 中不起作用

html - 如何在 css 矩形中获得加号?

python - 使用请求填写表单并检索结果

php - 使用 formdata.php 创建一个简单的表单。不显示值。取而代之的是一个空白页面。如何修复它?

python - 损坏的图像 - Google App Engine

javascript - 悬停时仅针对图像 CSS

html - CSS 样式方法