html - 不能中心形式?

标签 html css

所以 #container已经居中,但我似乎无法获得 <form>居中。我想让表单内的所有内容都水平居中,但由于某种原因它不起作用。我已经尝试了所有我知道的技巧。

<!-- Container Start -->
<div id="container">
  <h1 class="signup-header-text">SIGN UP</h1>
  <div class="clear"></div>
  <form class="signup-form" action="#" method="post">
    <div id="first_step">
      <div class="form">
        <label for="gender">You are:</label>
        <br />
        <select id="gender" name="gender" size="2">
          <option value="1">Male</option>
          <option value="2">Female</option>
        </select>
        <div class="clear"></div>
      </div>
      <div class="clear"></div>
      <input class="submit" type="submit" name="submit_first" id="submit_first" value="" />
    </div>
  </form>
<div id="progress_bar">
       <div id="progress"></div>
       <div id="progress_text">0% Complete</div>
</div>
</div>
<!-- Container End -->

我的 CSS

#container {
    height: 410px;
    min-height: 410px;
    min-width: 756px;
    width: 756px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -205px; /* Half the height */
    margin-left: -378px; /* Half the width */
    background: #e9e5e5;
    border: solid #dcdcdc 2px;
    outline: solid #c4c4c4 1px;
    -webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    -moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
    box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
}

最佳答案

添加文本对齐:居中;

#container {
height: 410px;
min-height: 410px;
min-width: 756px;
width: 756px;
overflow: hidden;
position: absolute;
top: 50%;
left: 50%;
margin-top: -205px; /* Half the height */
margin-left: -378px; /* Half the width */
background: #e9e5e5;
border: solid #dcdcdc 2px;
outline: solid #c4c4c4 1px;
-webkit-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
-moz-box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
box-shadow: 0px 5px 15px rgba(48, 50, 50, 0.28);
text-align: center;
}​

http://jsfiddle.net/xjL7t/

关于html - 不能中心形式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14167330/

相关文章:

html - 将图像作为边框适合任意大小的 div

css - 在 gulp 处理时处理 css 文件中的图像路径

html - 如何仅使用 CSS 在 <a> 元素内添加图标

javascript - 菜单样式的应用程序,例如 google.com Mobile

css - html 文件中缺少图像

python - 使用 BeautifulSoup 更新 HTML 文件

jquery - 在 jquery 或 css 中重新定位弹出窗口

html - Main 从 body 继承宽度

html - 两个显示表格单元格之间的边距

asp.net - ASP.NET 中的可折叠转发器