在HTML 5中对齐复选框

时间:2016-10-21 09:34:07

标签: html css3

我正在尝试用HTML创建一个登录页面。 无论我做什么,复选框及其文本都不会在同一行中一起出现。 我希望它看起来像那样:“[] text”而不是: “[](沿着一条线)文字”。 我在类似的帖子中尝试了很多建议,但似乎没什么用。

这是我的代码:

* {
    box-sizing: border-box;
}

*:focus {
    outline: none;
}
body {
    font-family: Arial;
    background-color: #3498DB;
    padding: 50px;
}
.login {
    margin: 20px auto;
    width: 300px;
}
.login-screen {
    background-color: #FFF;
    padding: 20px;
    border-radius: 5px
}

.app-title {
    text-align: center;
    color: #777;
}

.login-form {
    text-align: center;
}
.control-group {
    margin-bottom: 10px;
}

input {
    text-align: center;
    background-color: #ECF0F1;
    border: 2px solid transparent;
    border-radius: 3px;
    font-size: 16px;
    font-weight: 200;
    padding: 10px 0;
    width: 250px;
    transition: border .5s;
}

input:focus {
    border: 2px solid #3498DB;
    box-shadow: none;
}

.btn {
    border: 2px solid transparent;
    background: #3498DB;
    color: #ffffff;
    font-size: 16px;
    line-height: 25px;
    padding: 10px 0;
    text-decoration: none;
    text-shadow: none;
    border-radius: 3px;
    box-shadow: none;
    transition: 0.25s;
    display: block;
    width: 250px;
    margin: 0 auto;
}

.btn:hover {
    background-color: #2980B9;
}

.errorMsg{
    font-size: 12px;
    color: red;
}
.LabeledCheckboxGroup label, .LabeledCheckboxGroup input {
    float: none; /* if you had floats before? otherwise inline-block will behave differently */
    display: inline-block;
    vertical-align: middle;
}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Login</title>
    <!--<script src="script/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">-->
    <link rel="stylesheet" type="text/css" href="css/Login.css">
</head>
<body>
<div class="login">
    <div class="login-screen">
        <div class="app-title">
            <h1>Gridler</h1>
        </div>

        <div class="login-form">
            <div class="control-group">
                <input type="text" class="login-field" value="" placeholder="username" id="login-name">
                <label class="login-field-icon fui-user" for="login-name"></label>
                <input type="checkbox" checked name ="IsHuman"> Human Player
            </div>

            <a class="btn btn-primary btn-large btn-block" href="#" onclick="process()">login</a>
            <!--errorMsg below will later be filed with script and ajax to show a msg when a name is already exist-->
            <p class="errorMsg" href="#"></p>
        </div>
    </div>
</div>
</body>
</html>

谢谢, 帽儿

5 个答案:

答案 0 :(得分:0)

&#13;
&#13;
* {
    box-sizing: border-box;
}

*:focus {
    outline: none;
}
body {
    font-family: Arial;
    background-color: #3498DB;
    padding: 50px;
}
.login {
    margin: 20px auto;
    width: 300px;
}
.login-screen {
    background-color: #FFF;
    padding: 20px;
    border-radius: 5px
}

.app-title {
    text-align: center;
    color: #777;
}

.login-form {
    text-align: center;
}
.control-group {
    margin-bottom: 10px;
}

input {
    text-align: center;
    background-color: #ECF0F1;
    border: 2px solid transparent;
    border-radius: 3px;
    font-size: 16px;
    font-weight: 200;
     width: auto;
    padding: 10px 0;
    transition: border .5s;
}

input:focus {
    border: 2px solid #3498DB;
    box-shadow: none;
}

.btn {
    border: 2px solid transparent;
    background: #3498DB;
    color: #ffffff;
    font-size: 16px;
    line-height: 25px;
    padding: 10px 0;
    text-decoration: none;
    text-shadow: none;
    border-radius: 3px;
    box-shadow: none;
    transition: 0.25s;
    display: block;
    width: 250px;
    margin: 0 auto;
}

.btn:hover {
    background-color: #2980B9;
}

.errorMsg{
    font-size: 12px;
    color: red;
}
.LabeledCheckboxGroup label, .LabeledCheckboxGroup input {
    float: none; /* if you had floats before? otherwise inline-block will behave differently */
    display: inline-block;
    vertical-align: middle;
}
&#13;
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Login</title>
    <!--<script src="script/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">-->
    <link rel="stylesheet" type="text/css" href="css/Login.css">
</head>
<body>
<div class="login">
    <div class="login-screen">
        <div class="app-title">
            <h1>Gridler</h1>
        </div>

        <div class="login-form">
            <div class="control-group">
                <input type="text" class="login-field" value="" placeholder="username" id="login-name">
                <label class="login-field-icon fui-user" for="login-name"></label><br/>
                <input type="checkbox" checked name ="IsHuman"> Human Player
            </div>

            <a class="btn btn-primary btn-large btn-block" href="#" onclick="process()">login</a>
            <!--errorMsg below will later be filed with script and ajax to show a msg when a name is already exist-->
            <p class="errorMsg" href="#"></p>
        </div>
    </div>
</div>
</body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

添加

input.login-field {
    display: block;
    margin: 0 auto;
}

答案 2 :(得分:0)

将复选框及其文本放在div中。

从复选框中删除width属性。

将文本移动到自己的标签中。

为复选框和标签设置display:inline-block。

答案 3 :(得分:0)

您已将所有输入的宽度设置为250px,只需更改

即可
input {
text-align: center;
background-color: #ECF0F1;
border: 2px solid transparent;
border-radius: 3px;
font-size: 16px;
font-weight: 200;
padding: 10px 0;
width: 250px;
transition: border .5s;
}

#login-name {
text-align: center;
background-color: #ECF0F1;
border: 2px solid transparent;
border-radius: 3px;
font-size: 16px;
font-weight: 200;
padding: 10px 0;
width: 250px;
transition: border .5s;
}

答案 4 :(得分:0)

我已修改了您的代码段,请查看。

&#13;
&#13;
* {
    box-sizing: border-box;
}

*:focus {
    outline: none;
}
body {
    font-family: Arial;
    background-color: #3498DB;
    padding: 50px;
}
.login {
    margin: 20px auto;
    width: 300px;
}
.login-screen {
    background-color: #FFF;
    padding: 20px;
    border-radius: 5px
}

.app-title {
    text-align: center;
    color: #777;
}

.login-form {
    text-align: center;
}
.control-group {
    margin-bottom: 10px;
}

input {
    text-align: center;
    background-color: #ECF0F1;
    border: 2px solid transparent;
    border-radius: 3px;
    font-size: 16px;
    font-weight: 200;
    padding: 10px 0;
    width: 250px;
    transition: border .5s;
}

input:focus {
    border: 2px solid #3498DB;
    box-shadow: none;
}

input[type="checkbox"]
{
  width: 30px;
}

.checkbox {
   text-align: left;
  font-size: 14px;
  margin-top: 5px;
  }

.checkbox label {
   vertical-align: top;
  }

.btn {
    border: 2px solid transparent;
    background: #3498DB;
    color: #ffffff;
    font-size: 16px;
    line-height: 25px;
    padding: 10px 0;
    text-decoration: none;
    text-shadow: none;
    border-radius: 3px;
    box-shadow: none;
    transition: 0.25s;
    display: block;
    width: 250px;
    margin: 0 auto;
}

.btn:hover {
    background-color: #2980B9;
}

.errorMsg{
    font-size: 12px;
    color: red;
}
.LabeledCheckboxGroup label, .LabeledCheckboxGroup input {
    float: none; /* if you had floats before? otherwise inline-block will behave differently */
    display: inline-block;
    vertical-align: middle;
}
&#13;
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Login</title>
    <!--<script src="script/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css">-->
    <link rel="stylesheet" type="text/css" href="css/Login.css">
</head>
<body>
<div class="login">
    <div class="login-screen">
        <div class="app-title">
            <h1>Gridler</h1>
        </div>

        <div class="login-form">
            <div class="control-group">
                <input type="text" class="login-field" value="" placeholder="username" id="login-name">
                <label class="login-field-icon fui-user" for="login-name"></label>
              <div class="checkbox">
                <input type="checkbox" checked name ="IsHuman"> <label>Human Player</label>
                </div>
                
            </div>

            <a class="btn btn-primary btn-large btn-block" href="#" onclick="process()">login</a>
            <!--errorMsg below will later be filed with script and ajax to show a msg when a name is already exist-->
            <p class="errorMsg" href="#"></p>
        </div>
    </div>
</div>
</body>
</html>
&#13;
&#13;
&#13;