How to align 2 containers that lay on the center - html

I want to align this:
HTML view
to this but on the center of website:
Desired result
but It goes to left margin instead:
The reality
How can I make this one to be on the center of website?
I have tried using some combinations and different attributes but the result did not change.
.container{
text-align: center;
position:relative;
}
.inputArea{
margin: auto;
display: flow;
}
.deleteArea{
margin:auto;
display:inline-block;
}
<div class="container">
<div class="inputArea" >
<form th:action="#{/}" method="post">
<input type="text" th:id="inputWord" name="inputWord" />
<input type="text" th:id="inputTranslation" name="inputTranslation" />
<input type="text" th:id="language" name="language" value="English" />
<input type="submit" th:id="addWord" value="add" />
</form>
</div>
<div class="inputArea">
<form th:action="#{/delete}" method="post">
<input type="text" th:id="inputWordDelete" name="inputWordDelete" />
<input type="text" th:id="inputTranslationDelete" name="inputTranslationDelete" />
<input type="text" th:id="languageDelete" name="languageDelete" />
<input type="submit" th:id="deleteWord" value="delete" />
</form>
</div>
</div>
What should I change in my code to achieve the desired result?

Do you intend to achieve something like this? One option could be to use css grid...
.container{
text-align: center;
position: relative;
}
.inputArea form {
margin: auto;
display: inline-grid;
grid-template-columns: auto auto auto minmax(0px, 100px);
text-align: left;
}
<div class="container">
<div class="inputArea" >
<form th:action="#{/}" method="post">
<input type="text" th:id="inputWord" name="inputWord" />
<input type="text" th:id="inputTranslation" name="inputTranslation" />
<input type="text" th:id="language" name="language" value="English" />
<div><input type="submit" th:id="addWord" value="add" /></div>
</form>
</div>
<div class="inputArea">
<form th:action="#{/delete}" method="post">
<input type="text" th:id="inputWordDelete" name="inputWordDelete" />
<input type="text" th:id="inputTranslationDelete" name="inputTranslationDelete" />
<input type="text" th:id="languageDelete" name="languageDelete" />
<div><input type="submit" th:id="deleteWord" value="delete" /></div>
</form>
</div>
</div>

Here is another way to do it. Have you tried this?
.container {
width: 100%;
}
.container-inner {
margin: 0 auto;
display: table;
}
<div class="container">
<div class="container-inner">
<div class="inputArea" >
<form th:action="#{/}" method="post">
<input type="text" th:id="inputWord" name="inputWord" />
<input type="text" th:id="inputTranslation" name="inputTranslation" />
<input type="text" th:id="language" name="language" value="English" />
<input type="submit" th:id="addWord" value="add" />
</form>
</div>
<div class="inputArea">
<form th:action="#{/delete}" method="post">
<input type="text" th:id="inputWordDelete" name="inputWordDelete" />
<input type="text" th:id="inputTranslationDelete" name="inputTranslationDelete" />
<input type="text" th:id="languageDelete" name="languageDelete" />
<input type="submit" th:id="deleteWord" value="delete" />
</form>
</div>
</div>
</div>

Related

How to align input boxes in 2 lines

I'm doing a form where I want 3 input boxes to the left and to the right. Now, I copied the code from a past project of mine where it worked but now it wont work in this new project. I've tried every text-align and float I know about. I really don't know what to do anymore.
This is the code i have for this so far.
input[id=fname], input[id=lname], input[id=phone], input[id=city],i nput[id=email], input[id=birthday] {
width: 420px;
margin-bottom: 15px;
padding: 3px;
}
#left {
width: 40px;
display: inline-block;
box-sizing: border-box;
}
#right {
width: 440px;
display: inline-block;
float: right;
padding-left: 8px;
box-sizing: border-box;
}
<!doctype html>
<html>
<head>
<title>Employee Directory</title>
<link rel="stylesheet" type="text/css" href="css/Styles.css">
</head>
<body>
<div class="form">
<form method="post">
<div id="left">
<label>First Name</label>
<input id="fname" type="text" tabindex="1" >
<label>Phone</label>
<input id="phone" type="phone" tabindex="3">
<label>City</label>
<input id="city" type="text" tabindex="5">
</div>
<div id="right" class="box">
<label>Last Name</label>
<input id="lname" type="text" tabindex="2">
<label>Email</label>
<input id="email" type="email" tabindex="4">
<label>Birthday</label>
<input id="bday" type="date" tabindex="6">
</div>
</form>
</div>
</body>
</html>
You can simplify the HTML and CSS a lot here. Use display:grid to align everything:
form {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 9px 20px;
}
input {
display: block;
width: 100%;
}
<form class="form" method="post">
<label>First Name
<input name="fname" type="text">
</label>
<label>Last Name
<input name="lname" type="text">
</label>
<label>Phone
<input name="phone" type="phone">
</label>
<label>Email
<input name="email" type="email">
</label>
<label>City
<input name="city" type="text">
</label>
<label>Birthday
<input name="bday" type="date">
</label>
</form>
You should try to make it so your order of inputs is left to right down the page as tabbing from first name to Phone and then back up to last name is not very intuitive (Although fixed with tabindex this can be default).
Here is how I would do it.
input[id=fname], input[id=lname], input[id=phone], input[id=city],input[id=email], input[id=birthday] {
width: 50%;
margin-bottom: 15px;
padding: 3px;
}
#form_fields {
display:flex;
flex-wrap:wrap;
}
#form_fields label {
width:50%;
}
#form_fields label input {
width:50%;
}
<!doctype html>
<html>
<head>
<title>Employee Directory</title>
<link rel="stylesheet" type="text/css" href="css/Styles.css">
</head>
<body>
<div class="form">
<form method="post">
<div id="form_fields">
<label>First Name<br />
<input id="fname" type="text" />
</label>
<label>Last Name<br />
<input id="lname" type="text" />
</label>
<label>Phone<br />
<input id="phone" type="phone" />
</label>
<label>Email<br />
<input id="email" type="email" />
</label>
<label>City<br />
<input id="city" type="text" />
</label>
<label>Birthday<br />
<input id="bday" type="date" />
</label>
</div>
</form>
</div>
</body>
</html>

Why doesn't this div move using css?

I have a form inside a div. I want to move the div to the right, and I can do that if I use an inline style like this:
<div class="joinform-page" style="margin-left: 30%;>
I want to move it using margin-left: 30% in the css, not as an inline style because inline styles make media queries more difficult. But it ignores any margin changes I make in the css.
Here's the full html:
<div class="joinform-page">
<div class="form">
<form action="data_in.php" method="post" name='data_in' id='data_in'>
<input type="text" placeholder="Email" name="email_field" maxlength="60">
<input type="text" placeholder="First Name (optional)" name="firstname" maxlength="50">
<input type="text" placeholder="Last Name (optional)" name="lastname" maxlength="50">
<div><input type="hidden" id="password" name="password" value="pwdtemp"></div>
<div><input type="hidden" id="comments" name="comments" value="none"></div>
<button class="btn_class" style="color:rgb(255,255,255); background-color:rgb(25,25,25); text-align:center;" id="btn_submit" onclick="GetDate();">Submit Form</button><br><br><br>
<div style="padding-left:0%;">
<label class="container">
<span class="betajoinpage_cbx">Add me to your list</span>
<input type="hidden" name="custom_checkbox" value="No">
<input type="checkbox" id="ckbx" name="custom_checkbox" checked="checked" value="Yes"><span class="checkmark" style="color:blue;"></span>
</label></div><br>
</form>
</div>
</div>
Here's the relevant css class:
.joinform-page {
width: 80%;
padding: 0% 0 0;
margin-top: -2.5%;
margin-left: 30%; }
Why doesn't this div move when I use margin-left in the css,. not as an inline style.
Thanks for any help.
Actually It was working with the same piece of code.
If it still doesn't work, there might be styling for parent element or another styling for same element.
The CSS you have above works as you would expect. Please ensure your CSS is correctly imported like so:
<!-- Where FILE_NAME is the name of your .CSS file -->
<link rel="stylesheet" type="text/css" href="FILE_NAME.css">
.joinform-page {
width: 80%;
padding: 0% 0 0;
/*margin-top: -2.5%;*/
margin-left: 30%;
}
<div class="joinform-page">
<div class="form">
<form action="data_in.php" method="post" name='data_in' id='data_in'>
<input type="text" placeholder="Email" name="email_field" maxlength="60">
<input type="text" placeholder="First Name (optional)" name="firstname" maxlength="50">
<input type="text" placeholder="Last Name (optional)" name="lastname" maxlength="50">
<div><input type="hidden" id="password" name="password" value="pwdtemp"></div>
<div><input type="hidden" id="comments" name="comments" value="none"></div>
<button class="btn_class" style="color:rgb(255,255,255); background-color:rgb(25,25,25); text-align:center;" id="btn_submit" onclick="GetDate();">Submit Form</button><br><br><br>
<div style="padding-left:0%;">
<label class="container">
<span class="betajoinpage_cbx">Add me to your list</span>
<input type="hidden" name="custom_checkbox" value="No">
<input type="checkbox" id="ckbx" name="custom_checkbox" checked="checked" value="Yes"><span class="checkmark" style="color:blue;"></span>
</label></div><br>
</form>
</div>
</div>

how do i make the password and username tabs centerd to eachother

I was wandering if there is a way to center the password and username tab under eachother? Also if you see a way to make this code shorter pleas tell me. I am a noob at html so there is probably some wrongs in this code. Ty before hand, Lukas Mocko!
p.mom {
padding-top: 16em
}
p.dad {
padding-top: 1em
}
p.car {
padding-left: 56.5em
}
p.car {
padding-top: 1em
}
<center>
<head>
<style>
</style>
<form method="post" action="index.php" name="loginform">
<p class="mom">
<label for="login_input_username">имя пользователя</
</p class="mom">
<input id="login_input_username" class="login_input" type="text
name="user_name" required />
<p class="dad">
<label
for="login_input_password">     пароль</label>
<input id="login_input_password" class="login_input" type="password" name="user_password" autocomplete="off" required />
</p class="dad">
</center>
<p class="car">
<input type="submit" name="login" value="авторизоваться" />
</p class="car">
</form>
</head>
you can use display: flex; property of css to do this
HTML
<form method="post" action="index.php" name="loginform">
<div>
<label for="login_input_username">имя пользователя</label>
<input id="login_input_username" class="login_input" type="text" name="user_name" required />
</div>
<div>
<label for="login_input_password">пароль</label>
<input id="login_input_password" class="login_input" type="password" name="user_password" autocomplete="off" required />
</div>
<div>
<input type="submit" name="login" value="авторизоваться" />
</div>
</form>
CSS:
form{
flex: 1;
display: flex;
height: 250px;
align-items: center;
flex-direction: column;
justify-content: center;
}
form div{
margin-bottom: 10px;
}
form div label{
display: flex;
}
form div button{
display: flex;
}
You can use this code.
HTML:
<form method="post" action="index.php" name="loginform">
<div>
<label for="login_input_username">имя пользователя</label>
<input id="login_input_username" class="login_input" type="text" name="user_name" required />
</div>
<div>
<label for="login_input_password">пароль</label>
<input id="login_input_password" class="login_input" type="password" name="user_password" autocomplete="off" required />
</div>
<div>
<input type="submit" name="login" value="авторизоваться" />
</div>
</form>
CSS:
form{
flex: 1;
display: flex;
height: 250px;
align-items: center;
flex-direction: column;
justify-content: center;
}
form div{
margin-bottom: 10px;
}
form div label{
display: flex;
}
form div button{
display: flex;
}
You can try this:
<form method="post" action="index.php" name="loginform">
<div style="align-items:center; display: flex; flex-direction: column;">
<div>
<label for="login_input_username">имя пользователя</label><br/>
<input id="login_input_username" class="login_input" type="text"
name="user_name">
</div>
<div>
<label
for="login_input_password">пароль</label><br/>
<input id="login_input_password" class="login_input" type="password"
name="user_password" autocomplete="off" required />
</div>
<div>
<br />
<input type="submit" name="login" value="авторизоваться" />
</div>
</div>
</form>
p.dad, .car {
padding-top: 1em;
}
/* center div */
.form-center{
margin: auto;
width: 50%;
text-align: center;
}
<div class="form-center">
<form method="post" action="index.php" name="loginform">
<p class="mom">
<label for="login_input_username">имя пользователя</label>
</p>
<input id="login_input_username" class="login_input" type="text" name="user_name" required />
<p class="dad">
<label for="login_input_password">пароль</label>
</p>
<input id="login_input_password" class="login_input" type="password" name="user_password" autocomplete="off" required />
</center>
<p class="car">
<input type="submit" name="login" value="авторизоваться" />
</p>
</form>
</div>
EDITED: I change code.
CSS
form {
text-align:center;
}
table{margin: auto;}
HTML
<form method="post" action="index.php" name="loginform">
<table>
<tbody><tr>
<td><label for="login_input_username">имя пользователя</label></td>
<td><input id="login_input_username" class="login_input" type="text" name="user_name" required=""></td>
</tr>
<tr>
<td> <label for="login_input_password">пароль</label></td>
<td> <input id="login_input_password" class="login_input" type="password" name="user_password" autocomplete="off" required=""></td>
</tr>
</tbody></table>
</form>

Aligning form with multilined label? (HTML/CSS)

I am wanting to make a label on a form that is much longer than the other labels in the form appear on multiple lines. I then want to align the inputs to the labels on the colons of the labels.
Here is a picture of the current set up:
Basically, I need Releasse Date to appear as
Release Date
(YYYY-MM-DD): [input box]
HTML Code:
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date (YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>
CSS Code:
#songform {
margin: 20px;
}
label {
float: left;
width: 250px;
margin-top: 20px;
clear: right;
}
input{
margin-top: 20px;
}
#songsubmit {
margin-left: 80px;
}
Use display:inline-block and vertical-align:bottom. No floats or absolute positioning needed.
#songform {
margin: 20px;
}
#songform > div {
position: relative;
margin-top: 20px;
}
label {
display:inline-block;
width: 250px;
vertical-align:bottom;
}
#songsubmit {
margin-left: 80px;
}
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date<br>(YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>
I've made a fiddle with code for your case: http://jsfiddle.net/862xc2j1/
You can solve it with adding clear:left to each div wrapper for each form field block.
<div class="form-item">
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
.form-item {
clear: left;
}
To get this alignment next to the colon, you can use absolute positioning. Here is a working example - I made a few more changes to get it to work:
#songform {
margin: 20px;
}
#songform > div {
position: relative;
margin-top: 20px;
}
#songform > div:after {
/* Clearfix */
content:"";
display:table;
clear:both;
}
#songform > div > input {
position: absolute;
bottom: 0;
}
label {
float: left;
width: 250px;
clear: right;
}
#songsubmit {
margin-left: 80px;
}
<form action="http://localhost/songadded.php" method="post" id="songform">
<h4>Add a New Song</h4>
<div>
<label for="name">Name:</label>
<input type="text" name="name" size="30" value=""/>
</div>
<div>
<label for="artist">Artist:</label>
<input type="text" name="artist" size="30" value=""/>
</div>
<div>
<label for="album">Album:</label>
<input type="text" name="album" size="30" value=""/>
</div>
<div>
<label for="genre">Genre:</label>
<input type="text" name="genre" size="30" value=""/>
</div>
<div>
<label for="release_date" id="rdlabel">Release Date<br>(YYYY-MM-DD):</label>
<input type="text" name="release_date" size="30" value="" id="rdinput"/>
</div>
<div>
<label for="bpm">BPM:</label>
<input type="text" name="bpm" maxlength="3" value=""/>
</div>
<div id="songsubmit">
<input type="submit" name="submit" value="Add Song"/>
</div>
</form>

How do I get rid of the big margin between my labels and the input fields?

Below is my code, first of all:
How do I get rid of the big margin to the right that occurs between the labels and the input fields? I tried setting the margin-right to -150px which made it smaller but that just seems like an idiotic solution..
How can I remove the need to write <br /> to make them hop down a line automatically? I was told never to use <br />, it also seems messy.
HTML:
<div id="groupmepopup" class="popup">
<h4>Fill in your information so that you can be added.</h4>
<form action="" method="POST">
<label>In-game username:</label>
<input name="username" type="text"></input><br />
<label>Email:</label>
<input name="email" type="text"></input><br />
<label>Game:</label>
<input name="game" type="text"></input><br />
<input name="mySubmit" type="submit" value="Submit"></input>
</form>
</div>
CSS:
label {
display: block;
float: left;
width: 120px;
margin-right: 5px;
text-align: right;
}
You can try something like this
<div id="groupmepopup" class="popup">
<h4>Fill in your information so that you can be added.</h4>
<form action="" method="POST">
<p>
<label>In-game username:</label>
<input name="username" type="text"></input>
</p>
<p>
<label>Email:</label>
<input name="email" type="text"></input>
</p>
<p>
<label>Game:</label>
<input name="game" type="text"></input>
</p>
<p></p>
<input name="mySubmit" type="submit" value="Submit"></input>
</form>
</div>
and then the css
p label {
display: block;
float: left;
width: 120px;
margin-right: 5px;
}
p input{
float:right;
}
p{
clear:both;
}
form{
width:20em;
}
http://jsfiddle.net/V92PT/1/
But the fields part on table
like this
<div id="groupmepopup" class="popup">
<h4>Fill in your information so that you can be added.</h4>
<form action="" method="POST">
<table><tr><td><label>In-game username:</label></td>
<td> <input name="username" type="text"></input></td ></tr>
<tr><td> <label>Email:</label></td>
<td> <input name="email" type="text"></input></td></tr>
<tr><td> <label>Game:</label></td>
<td>
<input name="game" type="text"></input>
</td></tr>
</table>
<input name="mySubmit" type="submit" value="Submit"></input>
</form>
</div>
or add another <br/> after <label>In-game username:</label>
or use <p></P> for each row