Maor Gershkovitch Maor Gershkovitch - 1 month ago 5
HTML Question

aligning checkbox in HTML 5

I'm trying to create a login page in HTML.
no matter what i do, the checkbox and its text are not aliening together in a same line.
I want it to look like that: "[] text" instead of:
"[](going down a line) text".
I tried a lot of suggestions i saw in similar posts but nothing seems to works.

This is my code:



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





Thanks,
Maor

Aus Aus
Answer

Put the checkbox and its text inside a div.

Remove the width property from the checkbox.

Move the text into its own label.

set display: inline-block for both the checkbox and the label.

Comments