0

所以#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);
}
4

6 回答 6

1

添加了文本对齐:居中;

#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/

于 2013-01-05T01:02:55.463 回答
1

只需将文本居中即可。

#container {
    height: 410px;
    min-height: 410px;
    min-width: 756px;
    width: 756px;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    **text-align:center;**
    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);
}
于 2013-01-05T01:04:52.147 回答
0

添加

text-align:center;
float:center;
clear:center;

也适用于左右

于 2013-01-05T01:18:07.583 回答
0

尝试这个:

.signup-form {
    margin: 0 auto;
}
于 2013-01-05T00:54:09.487 回答
0

找到要居中的元素,设置宽度,然后margin: 0 auto在其上设置。

.signup-form {
  margin: 0 auto;
  width: 100px;
}

http://jsfiddle.net/EXLSJ/

如果您不想设置固定宽度,请按照以下说明“收缩包装”您的容器:如何使 div 不大于其内容?

于 2013-01-05T01:05:07.820 回答
0

添加text-align: center;

 #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;**
 }
于 2013-01-05T01:13:14.770 回答