2016-10-21 2 views
-2

Я пытаюсь создать страницу входа в HTML. независимо от того, что я делаю, флажок и его текст не сглаживаются вместе в одной строке. Я хочу, чтобы это выглядело так: «[] текст» вместо: «[] (идет по строке) текст». Я пробовал много предложений, которые я видел в подобных сообщениях, но ничего не работает.выравнивание флажка в HTML 5

Это мой код:

* { 
 
    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>

Спасибо, Maor

+0

Вы даете элемент ширину 250px, удалите его, и он должен работать нормально –

+0

вы добавили ширину по умолчанию для все входной теге ... просто добавить CSS для флажка, как это : 'input [type =" checkbox "] { width: auto; } ' –

ответ

0

Установите флажок и его текст внутри div.

Удалить свойство ширины из флажка.

Переместить текст на свой собственный ярлык.

set display: встроенный блок для флажка и этикетки.

0

* { 
 
    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; 
 
}
<!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>

0

Добавить

input.login-field { 
    display: block; 
    margin: 0 auto; 
} 
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; 
} 
0

Я редактировал фрагмент кода, пожалуйста, смотрите.

* { 
 
    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; 
 
}
<!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>

Смежные вопросы