Form field alignment issues using flexbox [duplicate] - html

This question already has an answer here:
Input field wrapping using flexbox
(1 answer)
Closed 1 year ago.
PROBLEM:
I'm having some alignment issues with this form.
CODE SNIPPET:
.form-container {
display: flex;
margin: 0 auto;
align-items: center;
justify-content: center;
}
.verification-form {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.verification-form .form-group {
display: flex;
flex-direction: row;
margin-bottom: 35px;
width: 100%;
}
.verification-form .form-group:nth-child(3) {
margin-bottom: 5px;
}
.form-group label {
text-align: right;
font-size: 11px;
font-weight: bold;
color: #484343;
margin-left: 10px;
max-width: 150px;
}
.form-group input {
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
}
#required::after {
content: "*";
color: #f06d41;
font-size: 28px;
}
.form-group input:hover {
border-color: #aa2c2f;
outline: 0;
}
.form-group input:focus {
border-color: #aa2c2f;
outline: 0;
}
input[type="checkbox"] {
width: 28px !important;
height: 28px !important;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
box-shadow: none;
text-align: center;
background: #ffffff;
flex: none;
padding: 0px 0px;
margin-left: 20px;
border: 2px solid #d2d2d2;
border-width: 2px;
transition: border-color 0.3s;
font-size: 18px;
cursor: pointer;
}
input[type="checkbox"]:checked:after {
content: "✔";
color: #aa2c2f;
<div class="form-container">
<div class="verification-form">
<div class="form-group">
<label>FIRST</label>
<input id="firstName" type="" name="firstName" value="" required />
<label>LAST</label>
<input id="lastName" type="" name="lastName" value="" required />
</div>
<div class="form-group" id="required">
<label>EMAIL</label>
<input id="email" type="email" name="email" value="" required />
</div>
<div class="form-group">
<label>PHONE</label>
<input id="phone" type="" name="phone" value="" required />
<label class="sms-label">SMS<br />OPT IN</label>
<input id="sms" type="checkbox" name="sms" value="" required />
</div>
<div class="form-group" id="required">
<label>STREET<br />ADDRESS</label>
<input id="address" type="text" name="address" value="" required />
</div>
<div class="legend">
<p>
<sub>*</sub>Required field
</p>
</div>
</div>
</div>
As you can see, the form looks wonky.
I feel like this is the culprit:
.form-group input {
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
}
I would like the form to align properly where all fields in a single column are the same size and aligned. I also want the rows with two form fields to be even with rows that have only one field.
I've tried excluding flex:3 with a static width, however, this is not the solution. Would appreciate any help in making this look better.
EDIT: Also open to a solution using CSS grid.

I did some changes in your code. You should use flex for the paten div for the form and if you give witdh:100% to the input fileds it will fit the container of its own. So here the html and css for your form.
Html:
<div class="form-container">
<div class="verification-form">
<div class="form-group" >
<label class="required">FIRST</label>
<input id="firstName" type="" name="firstName" value="" required />
<label class="required">LAST</label>
<input id="lastName" type="" name="lastName" value="" required />
</div>
<div class="form-group" id="required">
<label class="required">EMAIL</label>
<input id="email" type="email" name="email" value="" required />
</div>
<div class="form-group">
<label class="required">PHONE</label>
<input id="phone" type="" name="phone" value="" required />
</div>
<div class="form-group row">
<label class="sms-label required">SMS OPTION</label>
<input id="sms" type="checkbox" name="sms" value="" required />
</div>
<div class="form-group" id="required">
<label class="required" >STREET ADDRESS</label>
<input id="address" type="text" name="address" value="" required />
</div>
<div class="legend">
<p>
<sub class="required"></sub>Required field
</p>
</div>
</div>
</div>
CSS:
.verification-form .form-group:nth-child(3) {
margin-bottom: 5px;
}
.form-group {
display:flex;
flex-direction:column;
text-align:start;
justify-content:flex-start;
max-width:320px;
padding:10px;
}
.form-group.row {
flex-direction:row;
align-items:center;
margin-bottom:10px;
}
.form-group label {
text-align: start;
font-size: 11px;
font-weight: bold;
color: #484343;
margin-left: 20px;
margin-bottom:10px;
max-width: 200px;
}
.form-group input {
width:100%;
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
margin-bottom:10px;
}
.required::after {
content: "*";
color: #f06d41;
font-size: 16px;
}
.form-group input:hover {
border-color: #aa2c2f;
outline: 0;
}
.form-group input:focus {
border-color: #aa2c2f;
outline: 0;
}
.legend {
margin-left:20px;
}
input[type="checkbox"] {
width: 28px !important;
height: 28px !important;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
box-shadow: none;
text-align: center;
background: #ffffff;
flex: none;
padding: 0px 0px;
margin-left: 20px;
border: 2px solid #d2d2d2;
border-width: 2px;
transition: border-color 0.3s;
font-size: 18px;
cursor: pointer;
}
input[type="checkbox"]:checked:after {
content: "✔";
color: #aa2c2f;}

Related

How can I stop my form overlaping my header

<?php
// Start the session
session_start();
?>
<html>
<head>
<title>Student Registeration</title>
<link rel="stylesheet" src="text/css" >
<style>
.login-box
{
width:280px;
position:relative;
top:30%;
left:50%;
transform: translate(-50%,-50%);
color:black;
}
h1
{
margin: 0;
float:left;
font-size:38px;
border-bottom: 6px solid gold;
margin-bottom: 40px;
padding:0 0 20px;
text-align:center;
}
.login-box p
{
margin: 0;
padding: 0;
font-size: 18px;
}
.login-box input
{
width: 100%;
overflow: hidden;
margin-bottom: 20px;
margin: 8px 0;
padding:9px 0;
}
.login-box input\[type="text"\], input\[type="password"\], input\[type="email"\]
{
border: none;
outline: none;
border-bottom: 1px solid gold;
background: none;
color:gold;
font-size: 16px;
width:100%;
float:left;
}
.button
{
font-family: century gothic;
border: none;
color: white;
padding: 15px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 10px 2px;
cursor: pointer;
border-radius: 19px;
background-image: linear-gradient(to right, gold , black);
}
</style>
</head>
<body>
<?php
include'header.php';
?>
<div class="login-box">
<form method="post" action="authen.php" <?php echo $_SERVER\['PHP_SELF'\]; ?>>
<h1>Create Account</h1>
<p><b>Full Name : </b></p>
<input type="text" class="textarea" id="fname" name=" fname" placeholder="Full Name" style="width:100%;" name="fname" pattern="\[A-Za-z \]+" required >
<p><b>Email :</b></p>
<input type="email" class="textarea" id="email" placeholder="Email" style="width:100%;" name="email" pattern="\[a-z0-9._%+-\]+#\[a-z0-9.-\]+\.\[a-z\]{2,}$" required>
<p><b>Username :</b></p>
<input type="text" id="user" class="textarea" placeholder="Username" style="width:100%;" name="user" pattern="\[A-Za-z0-9\]{5,}" required>
<p><b>Phone :</b></p>
<input type="text" id="phno" class="textarea" placeholder="Phone Number" style="width:100%;" name="phno" pattern="\[0-9\]{10}" required>
<p><b>Password :</b></p>
<input type="password" id="pass" placeholder="Password" class="textarea" style="width:100%;" name="pass" pattern="\[A-Za-z0-9\]{6,}" required>
<p><b>Confirm Password :</b></p>
<input type="password" id="cpass" class="textarea" placeholder="Confirm Password" style="width:100%;" name="cpass" pattern="\[A-Za-z0-9\]{6,}" required>
<p><b>Choose the following:</b></p>
<input type="radio" class="textarea" id="pfaculty" name="Faculty" value="Permanent faculty" required >Permanent Faculty
<input type="radio" class="textarea" id="vfaculty" name="Faculty" value="Visiting faculty" required >Visiting Faculty
<input type="submit" name="submit" class="Button"id="btn" value="Submit">
</form>
</div>
</body>
</html>
header.css
/*Index CSS*/
body{
color:#008080;
font-family:Century Gothic;
position: relative;
}
/*Naavigation Bar*/
div{
height:70px;
}
a{
color: #f2f2f2;
text-align: center;
text-decoration: none;
}
#Name{
float: left;
color: #f2f2f2;
text-align: center;
padding: 2px 5px;
font-size: 30px;
margin-top:12px;
}
.header {
overflow: hidden;
background-color: black;
position: fixed;
width: 100%;
top: 0;
}
.links{
float: right;
display: block;
color: #f2f2f2;
text-align: center;
margin-top:10px;
text-decoration: none;
padding: 14px 16px;
font-size: 20px;
}
.links:hover {
background-color: white;
color: #008080;
border-radius: 10px;
transition: 0.2s;
}
.header .icon {
display: none;
}
#media screen and (max-width: 600px) {
.links.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.header.responsive {
position: relative;
}
.header.responsive a {
float: none;
display: block;
text-align: left;
}
}
]1]1
Here in this code I have problem that my form overlaps my header
When I scroll down in the page it scrolls the form and overlap the header.
As I have given a picture you can see my form overlaps my header which should not happen. It should not crossover the header thats the problem.
And my radion button text is also not coming in proper format I have tried a lot things but it is not happening. So please anyone can resolve this error.
Give z-index (any value you want but greater than your form) to your header and if there is no position property in your header, add position: relative.

Centering the checkbox in a line [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 3 years ago.
I would like to center the checkbox in a line with text next to it.
I've tried already style="text-align: center;" in <div> but it doesn't work.
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2)
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail" />
<input type="password" name="password" id="password" placeholder="password" />
<button>Create account</button>
<div style="text-align: center;">
<input type="checkbox" name="consent" id="consent" />
<label for="consent">I agree to whatever you want me to agree</label>
</div>
</form>
At the moment it looks like this in the attached picture. So can someone please guide me on how to center the checkbox in a line?
here
Please add below line only your css class, not need to change in html you written:
vertical-align: middle;
position: relative;
bottom: 1px;
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2);
vertical-align: middle;
position: relative;
bottom: 1px;
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail"/>
<input type="password" name="password" id="password" placeholder="password"/>
<button>Create account</button>
<div style="text-align: center;">
<input type="checkbox" name="consent" id="consent"/>
<label for="consent">I agree to whatever you want me to agree</label>
</div>
</form>
Just put the checkbox in the tag and use
display: flex;
align-items: center;
on the label
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2)
}
input:checked[type="checkbox"] {
background-color: transparent;
}
label {
display: flex;
align-items: center;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail" />
<input type="password" name="password" id="password" placeholder="password" />
<button>Create account</button>
<div>
<label for="consent"><input type="checkbox" name="consent" id="consent" />I agree to whatever you want me to agree</label>
</div>
</form>
Use align-items property.
div { display: flex; align-items: center; } //immediate parent of checkbox and label
For parent div of input add the below style property
.div{
Display:inline-flex;
}
Or you can add the below code
<label for="input" ><input type="checkbox" name="input" /></label>
Try position:relative and bottom:**px as per your need
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width:15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2);
margin:0;
bottom:-3.5px;
position:relative
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail"/>
<input type="password" name="password" id="password" placeholder="password"/>
<button>Create account</button>
<div style="text-align: center;display:inline;">
<input type="checkbox" name="consent" id="consent" >
<label for="consent" > I agree to whatever you want me to agree</label>
</div>
</form>

How can I get the label text to the left of the input field?

I am not able to understand how I can get the label from top of the input field to the left. The label text is on top of the input field. How can I get it to the left of the input field for the contact information part? Any help would be appreciated. Thanks a lot.
This is my code:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can reset width and display on inputs and/or use float.
It can be a reset at any time or within the mediaquerie.
You can also filter within which fieldset you need this reset to be effective.(example below)
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can use display:flex with a container for each lines
.line
{
display:flex;
align-items:center;
}
.line label
{
min-width:200px;
}
input
{
flex:1;
margin:10px;
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<div class="line">
<label for="inputfield">Full Name :</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
</div>
<div class="line">
<label for="inputfield1">Email Address :</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
</div>
<div class="line">
<label for="inputfield2">Phone Number :</label>
<input type="text" name="phonenumber" id="inputfield2">
</div>
<div class="line">
<label for="inputfield3">Street Address :</label>
<input type="text" name="streetaddress" id="inputfield3">
</div>
<div class="line">
<label for="inputfield4">City :</label>
<input type="text" name="city" id="inputfield4">
</div>
<div class="line">
<label for="stateselect">State :</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
</div>
<div class="line">
<label for="zipcode">Zip Code :</label>
<input type="text" name="zipcode" id="zipcode">
</div>
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
Swap your labels and inputs to get desired result:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<label>HTML News</label><input type="checkbox" name="htmlnews"><br><br>
<label>CSS News</label><input type="checkbox" name="css"><br><br>
<label>Javascript News</label><input type="checkbox" name="javascript"><br><br>
<label>Newsletter format</label><br><br>
<label>HTML</label><input type="radio" name="newsletter" value="html"><br><br>
<label>Plain Text</label><input type="radio" name="newsletter" value="plaintext"><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can do this fairly easily:
Full Name: <input type="text" name="fullname" placeholder="Required" id="inputfield">
This will just make the text appear to the left side of the input itself.
I used this method for a newsletter input I was doing:
Name: <input id="nameInput" type="text" name="name" required><br>

Align 2 items side-by-side in a flex column

I am very new to flex. But I'm loving it so far. The question I have is, how do I align two items side-by-side when the parent has flex-direction: column;?
I have pasted my HTML and Sass code here along with screenshots.
I have a form like so:
// manage.html
<div class="form2" hidden>
<div class="message" hidden></div>
<form id="updateUserForm" action="https://someaction.com" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton"></button>
</form>
</div>
That is styled like so:
// style.scss
.form2 {
#updateUserForm {
display: flex;
flex-direction: column;
}
label {
text-align: center;
}
input {
border-style: solid;
border-color: $black;
color: $black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
}
input:focus::-webkit-input-placeholder {
color: transparent;
}
input:focus:-moz-placeholder {
color: transparent;
}
input:focus::-moz-placeholder {
color: transparent;
}
input:focus:-ms-input-placeholder {
color: transparent;
}
a,
button {
border: none;
color: $white;
background-color: $blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
display: inline-block;
align-self: flex-start;
cursor: pointer;
}
}
Here is the output:
I would like to align 'Cancel' link and 'Reactivate' button side by side. I tried the following:
// style.scss
a {
align-self: flex-start;
}
button {
align-self: flex-end;
}
This only slides the elements to left and right respectively without being on the same line. Here is the output I wish to get:
Any suggestions on how to reach my expected output?
You can just use flex-wrap: wrap with row direction and set flex: 0 0 100% on inputs.
form {
display: flex;
flex-wrap: wrap;
}
input {
flex: 0 0 100%;
}
<div class="form2">
<div class="message"></div>
<form id="updateUserForm">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton">Lorem</button>
</form>
</div>
Just place them in a container and change direction.
#updateUserForm {
display: flex;
flex-direction: column;
}
label {
text-align: center;
}
input {
border-style: solid;
border-color: black;
color: black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
}
input:focus::-webkit-input-placeholder {
color: transparent;
}
input:focus:-moz-placeholder {
color: transparent;
}
input:focus::-moz-placeholder {
color: transparent;
}
input:focus:-ms-input-placeholder {
color: transparent;
}
/*Just place them in a container and change direction*/
#button_container{
display:flex;
}
a,
button {
border: none;
color: white;
background-color: blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
display: inline-block;
align-self: flex-start;
cursor: pointer;
text-transform: uppercase;
}
<div class="form2">
<div class="message" hidden></div>
<form id="updateUserForm" action="https://someaction.com" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
<!--Just place them in a container and change direction -->
<div id="button_container">
Cancel
<button type="submit " class="updateButton">Reactivate</button>
<div>
</form>
</div>
With the existing markup, using flex-direction: column, you can't make those two "buttons" align side-by-side.
One way is to change to row wrap and make all the input + label 100% width, which can be done with either width: 100% (used below) or flex-basis: 100%.
With that the items being 100% wide will stack vertical and the rest horizontal (unless their total width doesn't exceed 100%)
Stack snippet
form {
display: flex;
flex-wrap: wrap;
}
label {
text-align: center;
width: 100%;
}
input {
border-style: solid;
border-color: black;
color: black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
width: 100%;
}
a,
button {
border: none;
color: white;
background-color: blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
<div class="form2">
<div class="message"></div>
<form id="updateUserForm" action="https://api.ghjobssubscribe.com/manage/update" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton">Submit</button>
</form>
</div>

How to move form to center of page

I am creating a registration form and am wondering how can I move the whole form to the center of the page? right now its all on the left side of the container, I want it to look a bit something like this: https://id2.s.nfl.com/fans/register?returnTo=http%3A%2F%2Fweeklypickem.fantasy.nfl.com%2F
#Regcontainer {
width: 1200px;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> </h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label>FIRST NAME</label>
<input type="text" name="FName" />
<label>LAST NAME</label>
<input type="text" name="SNAME" />
<br/>
<label>EMAIL ADDRESS</label> <input id="email" name="email" type="text" />
<BR/>
<label>CREATE YOUR USERNAME</label> <input name="uname" type="text" /> <br/>
<label>CREATE PASSWORD</label> <input name="pass" type="password" />
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Here is the solution I came up with... but what does it do?
#Registercontainer needs to be on the center of the page. Meaning, your fixed with of 1200px is not going to work too well. I took the approach of reducing the size of your from container to give a better look and feel like this:
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
/* ... your other properties here ... */
}
Another note, your <label> needs the for attribute as specified in this article.
Let me know if you have any questions, FYI there are many ways to make this work for you.
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
padding: 15px;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> Register With NackStack</h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label for="fname">FIRST NAME</label>
<input type="text" name="FName" id="fname" />
<br/>
<label for="sname">LAST NAME</label>
<input type="text" name="SNAME" id="sname" />
<br/>
<label for="email">EMAIL ADDRESS</label>
<input id="email" name="email" type="text" />
<br/>
<label for="uname">CREATE YOUR USERNAME</label>
<input name="uname" type="text" id="uname" />
<br/>
<label for="password">CREATE PASSWORD</label>
<input name="pass" type="password" id="password"/>
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Add margin:auto and a fixed width to the parent <div>. Example:
<div id="Registercontainer" style="margin-left:auto;margin-right:auto;width:250px">
Fiddle:
https://jsfiddle.net/mwatz122/g9ay26x3/
#Registercontainer {
text-align: center;
}
Please try this. It might help.
Put your form within a <div> like this:
<div align="center">
<!-- insert code here -->
</div>
Then in the CSS, add
form {
text-align: left;
}