定位一个css按钮

时间:2012-04-23 19:22:20

标签: css html5

我想在下一行显示一个按钮。但我试图使用按钮的属性“position”和“line-height”但没有任何改变。我希望它在名字的输入文本下的下一行的中心 the button i want to move it to the next line

这是我的代码:

css文件:

#popup {
font-family: 'Orbitron', serif;
font-size: 28px;
font-weight: 700;     
text-shadow: 0px 1px 2px #fff;

color: #222;

position: absolute;   
width: 100%;
height: 100%;
top: 0;
left: 0;

background: rgba(0,0,0,.5);

display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;          

-webkit-transition: all .5s ease-in;}

   #popup h1 {
font-weight: 400;
   }

   #popup-box {
width: 400px;
height: 300px;
background: #ccc url(../images/popup_bg.jpg);

border-radius: 10px;

position: relative;

-webkit-box-shadow: 0 5px 5px #333;

display: -webkit-box;
-webkit-box-pack: center;
-webkit-box-align: center;

-webkit-transition: all .5s ease-in;}

    #popup-box small {
font-size: .6em; }


   #popup.hide {
background: rgba(0,0,0,0);
visibility: hidden;     
    }
     #popup.hide #popup-box{
margin-top: -800px;}


  #popup-box a.button {
background: white;
border-radius: 10px;
display: block;
font-size: 30px;
margin: 230px auto 0;
padding: 10px;
width: 50px;
border: 3px solid #006438;
color:#006438;
text-decoration:none;
cursor:pointer;}

html文件:

<section id="popup">
    <div id="popup-bg">
    </div>
 <div id="popup-box">   
 <p><a id="gamelogin1" class="button"   href="">choose Name</a></p>
 <p><a id="gamelogin2" class="button"   href="">New Name</a></p>
 </div>
</section>

<section id="popupName" class="hide">
   <div id="popup-bg">
    </div>
 <div id="popup-box">   
 <label for="firstName">Your Name :</label>
<input type="text" name="firstName" size="20" maxlength="40"  id="firstName" />

 **<p><a id="validatelogin" class="button"  href="">Validate</a></p> //this is the //button i want to change**
</div>
</section>

3 个答案:

答案 0 :(得分:2)

在输入字段后添加分隔线(<br>):

<input type="text" name="firstName" size="20" maxlength="40"  id="firstName" /><br>

有些人认为<br>代码应该自我关闭:<br />,但这不是必需的。

要使其居中,请使用此CSS:

#validatelogin {
    width:100px;
    margin: 0 auto;
}

将宽度设置为按钮的适当宽度;必须修复它才能使margin: 0 auto;起作用。

答案 1 :(得分:1)

我不确定我是否理解你的问题,但也许你可以在按钮之前使用它

<div class="both"></div>

在css中

.both{
clear: both;
}

答案 2 :(得分:1)

你只需要 input[type=text] { display:block; }#validatelogin{ display:block; } 在你的CSS中。这将解决你的问题