将文本字段对齐到右侧html表单css

时间:2013-06-20 20:50:57

标签: css forms html alignment

我正在尝试将表单的文本字段对齐到包含它们的div的右侧。我有这个用于css:

application.css

#loginform {
    width: 400px;
    height: 300px;
    background: rgba(237,191,92, 1);
    margin-left: 0px;
    padding: 10px;
}

#usertext, #passtext {
    text-align: left;
}

#loginuser, #loginpass {
    text-align: right;
}

#submitbutton {
    text-align: center;
}

这是我的HTML:

indexform.php

<div id="loginform">
<form id="login" method="post" action="checklogin.php">
    <h1>Member Login</h1>
    <div id="usertext">
        <p>Username:</p>
    </div>
    <div id="passtext">
        <p>Password:</p>
    </div>
    <div id="loginuser">
        <input name="myusername" type="text" id="myusername">
    </div>
    <div id="loginpass">
        <input name="mypassword" type="password" id="mypassword">
    </div>
    <div id="submitbutton">
        <input type="submit" name="Submit" value="Login">
    </div>
</form>
</div>

现在发生了什么:

Username:
Password:

|--username textfield--|
|--password textfield--|

|-login button-|

文本字段应排列在“用户名:”和“密码:”标签的右侧。

1 个答案:

答案 0 :(得分:4)

我做了这个

DEMO

 <div id="loginuser">
    <input name="myusername" type="text" id="myusername">
</div>
<div id="usertext">
    <p>Username:</p>
</div>
<div id="loginpass">
    <input name="mypassword" type="password" id="mypassword">
</div>
<div id="passtext">
    <p>Password:</p>
</div>

#loginuser, #loginpass {
    float: right;
}