inline form to vertical - html

I have this form. I would like that until 768px width the form is inline, and afterwords the form should be vertical.
I am a little bit in doubt, if I have to set up a breakpoint, or bootstrap has a function that does that? As it is now, the form keeps being inline.
Does anybody knows how I can do that?
HTML
<div class="sign-up">
<p class="sub-header">#Helpers.GetText(CurrentPage, "signupHeaderText", CurrentPage.Parent)</p>
<form id="signupForm">
<div class="form-group">
<label class="sr-only" for="name">#Helpers.GetText(CurrentPage, "signupNameFieldText", CurrentPage.Parent)</label>
<input type="text" class="form-control" placeholder="#Helpers.GetText(CurrentPage, "signupNameFieldText", CurrentPage.Parent)" id="name" name="name" required />
</div>
<div class="form-group">
<label class="sr-only" for="email">#Helpers.GetText(CurrentPage, "signupEmailFieldText", CurrentPage.Parent)</label>
<input type="email" class="form-control" id="email" name="email" placeholder="#Helpers.GetText(CurrentPage, "signupEmailFieldText", CurrentPage.Parent)" required/>
</div>
<input type="text" id="Channel" name="Channel" style="display: none;" />
<input type="text" id="Campaign" name="Campaign" style="display: none;" />
<button type="submit" class="btn btn-default active">#Helpers.GetText(CurrentPage, "signupCtaButtonText", CurrentPage.Parent)</button>
</form>
</div>
SCSS:
.sign-up {
padding: $grid-gutter-width;
margin-bottom: $grid-gutter-width;
border-radius: 5px;
background-color: $white3;
.form-control {
box-shadow: none;
border-color: $white4;
}
.error {
border: 1px red solid;
}
label {
&#name,
&#email {
&-error {
display: none !important;
}
}
}
.btn {
margin: 0;
padding-top: 10px;
padding-bottom: 10px;
border: none;
width: 100%;
}
}
.signup-wide {
padding-top:15px;
form {
display: flex;
justify-content: space-between;
.form-group {
width: 33%;
height: 40px;
max-width: 200px;
input {
height: 100%;
}
}
.btn {
padding-top: 10px;
padding-bottom: 10px;
height: 40px;
width: 33%;
}
}
}

Bootsrap has system class for this, use <form class="form-inline">

Related

HTML/CSS: How to make the certain input fields on the same line in the form?

I'm working on a hotel reservation webpage, and having trouble aligning the input/select fields. For example, my current code shows the first name and the last name in two different lines, but I want to have them all together. This is my form looks like with my code:
first name
last name
address 1
address 2
city
state
zip
And below is how I wanted it to be:
first name last name <<----
address 1
address 2
city state <<----
zip
From my research I was able to do similarly by using display: inline-block, so I tried using it in my code as below, but it does not change anything. What am I doing wrong here?
#mainContainer {
width: 1139px;
display: flex;
justify-content: center;
padding: 0;
margin: auto;
text-align: center;
}
#formContainer {
max-width: 1000px;
width: 100%;
height: 100%;
margin-top: 110px;
background-color: white;
}
#contact {
padding-top: 25px;
}
#customerInformationForm {
width:50%;
float:left;
margin-bottom: 50px
}
#contact input {
width: 70%;
border: 1px solid #ccc;
background: #FFF;
margin: 0 0 5px;
padding: 10px;
}
#contact select {
width: 70%;
border: 1px solid #ccc;
background: #FFF;
margin: 0 0 5px;
padding: 10px;
}
#contact input [class="customerFullName"] {
display: inline-block;
width: 50%;
}
<div id="mainContainer">
<div id="formContainer">
<form id="contact" action="" method="post">
<div id="customerInformationForm">
<input class="customerFullName" placeholder="First name" type="text">
<input class="customerFullName" placeholder="Last name" type="text">
<input placeholder="Address 1" type="text">
<input placeholder="Address 2" type="text">
<input placeholder="City" type="text">
<select id="state" name="state">
<option value="State" selected>State</option>
<option value="Alabama">AL</option>
<option value="Alaska">AK</option>
<option value="Arizona">AZ</option>
</select>
<input placeholder="ZIP" type="text">
</div>
</form>
</div>
</div>
You made a little mess about all those "width" declarations. You made your div #customerInformationForm "width" for a half of a parent (50% width). Then you inserted in that div your first, last name etc. inputs, and set up their width for 70% of the parent, which actually made no possible, to insert two inputs side by side (70% + 70% equals more than 100%, so it displays in new line). Reconsider using all these width declarations, below you have a little start how you may handle it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#mainContainer {
width: 1139px;
display: flex;
justify-content: center;
padding: 0;
margin: auto;
text-align: center;
}
#formContainer {
max-width: 1000px;
width: 100%;
height: 100%;
margin-top: 110px;
background-color: white;
}
#contact {
padding-top: 25px;
}
#customerInformationForm {
/* width:50%;*/
float:left;
margin-bottom: 50px;
background-color: red;
}
#contact input {
width: 35%;
border: 1px solid #ccc;
background: #FFF;
margin: 0 0 5px;
padding: 10px;
}
#contact input:nth-child(3),
#contact input:nth-child(4) {
width: 70%;
}
#contact select {
width: 35%;
border: 1px solid #ccc;
background: #FFF;
margin: 0 0 5px;
padding: 10px;
}
#contact #customerInformationForm input .customerFullName {
display: inline-block;
width: 70%;
}
</style>
</head>
<body>
<div id="mainContainer">
<div id="formContainer">
<form id="contact" action="" method="post">
<div id="customerInformationForm">
<input class="customerFullName" placeholder="First name" type="text">
<input class="customerFullName" placeholder="Last name" type="text">
<input placeholder="Address 1" type="text">
<input placeholder="Address 2" type="text">
<input placeholder="City" type="text">
<select id="state" name="state">
<option value="State" selected>State</option>
<option value="Alabama">AL</option>
<option value="Alaska">AK</option>
<option value="Arizona">AZ</option>
</select>
<input placeholder="ZIP" type="text">
</div>
</form>
</div>
</div>
</body>
</html>
Use semantic tags like fieldset to you advantage here to group elements. I also champion the proper use of label, not hijacking the place holder attribute for that purpose.
The example below could use a bit of style tidying but it will give you the idea.
It uses flexbox to achieve inlining the field where required.
#customerInformationForm {
padding-top:2em;
}
fieldset {
border: none;
position:relative;
}
#customerInformationForm fieldset {
padding-left:0;
}
#customerInformationForm {
background-color:#DDD;
}
#customerInformationForm > fieldset {
background-color:#EEE;
padding: 1.5em 1em;
margin-bottom: 0.5em;
border-radius:5px;
}
input, select {
width:100%;
}
legend {
font-weight: bold;
padding-left: 0;
position:absolute;
top:0;
}
label {
display: block;
}
.flex {
display:flex;
align-items:stretch;
}
.flex > .form_group {
flex:1;
}
.form_group {
margin-right:10px;
}
<div id="mainContainer">
<div id="formContainer">
<form id="contact" action="" method="post">
<fieldset id="customerInformationForm">
<legend>Customer Information</legend>
<fieldset class="customer_name flex">
<legend>Customer Name</legend>
<div class="form_group">
<label for="firstName">First Name</label>
<input class="customerFullName" id="firstName" placeholder="Eg: John" type="text">
</div>
<div class="form_group">
<label for="lastName">Last Name</label>
<input class="customerFullName" placeholder="Eg: Smith" id="lastName" type="text">
</div>
</fieldset>
<fieldset class="address">
<legend>Address</legend>
<div class="form_group">
<label for="address1">Address 1</label>
<input type="text" id="address1">
</div>
<div class="form_group">
<label for="address1">Address 2</label>
<input type="text">
</div>
<fieldset class="city_state flex">
<div class="form_group">
<label for="City">City</label>
<input type="text" id="City">
</div>
<div class="form_group">
<label for="state">State</label>
<select id="state" name="state">
<option value="" selected></option>
<option value="Alabama">AL</option>
<option value="Alaska">AK</option>
<option value="Arizona">AZ</option>
</select>
</div>
</fieldset>
<div class="form_group">
<label for="zip">Zip</label>
<input id="zip" type="text">
</div>
</fieldset>
</fieldset>
</form>
</div>
</div>

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>

Insert check icon inside input box when text is present

I am attempting to insert a green check icon when text is inside an input box. I am trying to do this by adding in a fa-fa icon, but it does not seem to be working. In addition, I would like to place a red x icon inside the input box if the email is not valid. If someone has any insight how to do this your help would be greatly appreciated! Fiddle and image are attached.
Green Check and Rex x icons
JsFiddle
<form action="">
<div class="container" id="container">
<label>First Name
<input id="first_name" maxlength="40" name="first_name" size="20" type="text"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>Last Name
<input id="last_name" maxlength="80" name="last_name" size="20" type="text">
</label>
<label>Email
<input id="email" maxlength="80" name="email" size="20" type="text"><i class="fa fa-times-circle-o" aria-hidden="true"></i>
<!-- <span class="msg error">Wrong email!</span>
<span class="msg success">Correct email!</span> -->
</label>
<label>Phone
<input id="phone" maxlength="40" name="phone" size="20" type="text">
</label>
<label>City
<input id="city" name="city" maxlength="40" size="20" type="text">
</label>
<label>State/Province
<input id="state" maxlength="20" name="state" size="20" type="text">
</label>
<label id="company">Company
<input id="company" name="company" type="text">
</label>
<label>Comments
<textarea name="" id="" cols="30" rows="10"></textarea>
<button type="submit" name="submit">SUBMIT</button>
</label>
</div>
</form>
body {
color: #fff;
background-color: #f78e2a;
text-align: center;
}
form {
color: #fff;
background-color: #f78e2a;
text-align: center;
font-family: Lato;
}
* {
box-sizing: border-box;
}
h1 {
font-size: 20px;
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
background-color: #f9a558;
border: 1px solid #fff;
}
input[type="text"]:focus {
background-color: #fff;
}
input[type="text"]:visited {
background-color: #fff;
}
.container {
display: flex;
flex-direction: column;
padding: 5px 0;
margin-left: 10%;
margin-right: 10%;
}
textarea {
width:100%;
background-color: #f9a558;
border: 1px solid #fff;
}
textarea:focus {
background-color: #fff;
}
#company {
flex-basis: 100%;
max-width: 100%;
}
label:nth-last-child(-n+2)
{
flex-basis: 100%;
max-width: 100%;
}
select, label {
height: 50px;
width: 48%;
margin: 2% 1%;
text-align: left;
}
button {
margin-top: 10px;
background-color: #B9B9B9;;
color: #959595;
border-radius: 6px;
width: 120px;
height: 35px;
margin-left: 1%;
display: block;
}
.fa fa-check-circle {
color: green;
}
button:focus{
background-color: #fff;
color: #f78e2a;
}
#media (max-width: 426px) {
label {
width: 98%;
}
}
#media (min-width: 426px) {
.container {
flex-direction: row;
flex-wrap: wrap;
align-self: flex-start;
}
}
A way to do this using javascript is to check keyup on the inputs, and if there is a value, show the icon. I'm using jQuery below.
And for your email, you need to use some sort of validation pattern - if the email input has content, show a red icon by default, but if it matches the validation pattern, change the icon to green. I got the email validation regex from How to validate email address in JavaScript?
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
$('input[type="text"]').on('keyup', function() {
if ($(this).val().trim() != '') {
if ($(this).is('#email')) {
if (validateEmail($(this).val())) {
$(this).attr('data-valid','valid');
} else {
$(this).attr('data-valid','error');
}
} else {
$(this).attr('data-valid','valid');
}
} else {
$(this).removeAttr('data-valid');
}
});
body {
color: #fff;
background-color: #f78e2a;
text-align: center;
}
form {
color: #fff;
background-color: #f78e2a;
text-align: center;
font-family: Lato;
}
* {
box-sizing: border-box;
}
h1 {
font-size: 20px;
text-align: center;
}
input[type="text"] {
width: 100%;
padding: 10px;
background-color: #f9a558;
border: 1px solid #fff;
}
input[type="text"]:focus {
background-color: #fff;
}
input[type="text"]:visited {
background-color: #fff;
}
.container {
display: flex;
flex-direction: column;
padding: 5px 0;
margin-left: 10%;
margin-right: 10%;
}
textarea {
width: 100%;
background-color: #f9a558;
border: 1px solid #fff;
}
textarea:focus {
background-color: #fff;
}
#company {
flex-basis: 100%;
max-width: 100%;
}
label:nth-last-child(-n+2) {
flex-basis: 100%;
max-width: 100%;
}
select,
label {
height: 50px;
width: 48%;
margin: 2% 1%;
text-align: left;
}
button {
margin-top: 10px;
background-color: #B9B9B9;
;
color: #959595;
border-radius: 6px;
width: 120px;
height: 35px;
margin-left: 1%;
display: block;
}
.fa fa-check-circle {
color: green;
}
button:focus {
background-color: #fff;
color: #f78e2a;
}
#media (max-width: 426px) {
label {
width: 98%;
}
}
#media (min-width: 426px) {
.container {
flex-direction: row;
flex-wrap: wrap;
align-self: flex-start;
}
}
label {
position: relative;
}
.fa {
position: absolute;
bottom: 0;
right: 0;
transform: translate(-50%, -45%);
opacity: 0;
transition: opacity .5s, color .5s;
}
[data-valid] + .fa {
opacity: 1;
}
[data-valid="valid"] + .fa {
color: green;
}
[data-valid="error"] + .fa {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="">
<div class="container" id="container">
<label>First Name
<input id="first_name" maxlength="40" name="first_name" size="20" type="text"><i class="fa fa-check-circle" aria-hidden="true"></i>
</label>
<label>Last Name
<input id="last_name" maxlength="80" name="last_name" size="20" type="text">
</label>
<label>Email
<input id="email" maxlength="80" name="email" size="20" type="text"><i class="fa fa-times-circle-o" aria-hidden="true"></i>
<!-- <span class="msg error">Wrong email!</span>
<span class="msg success">Correct email!</span> -->
</label>
<label>Phone
<input id="phone" maxlength="40" name="phone" size="20" type="text">
</label>
<label>City
<input id="city" name="city" maxlength="40" size="20" type="text">
</label>
<label>State/Province
<input id="state" maxlength="20" name="state" size="20" type="text">
</label>
<label id="company">Company
<input id="company" name="company" type="text">
</label>
<label>Comments
<textarea name="" id="" cols="30" rows="10"></textarea>
<button type="submit" name="submit">SUBMIT</button>
</label>
</div>
</form>
First, you have your input and i tags inside label. This needs to be fixed. After that's complete, you should create a parent div for each field. This will allow you to use position: absolute; for the icons.
Something like this:
HTML
<div class="field">
<label>First Name</label>
<input id="first_name" maxlength="40" name="first_name" size="20" type="text" />
<i class="fa fa-check-circle" aria-hidden="true"></i>
</div>
CSS
.field {
position: relative;
margin: 10px;
}
.field i.fa {
position: absolute;
top: 5px;
right: 5px;
}

HTML/CSS sign up form

I am currently working on creating a sign up form html/css. I realised that different browsers work differently on the width of inputs. How can i rectify this issue and make sure that my sign up form is compatible with all browsers. My sign up form works perfectly for chrome as it is where i do coding on.
ul {
background-color: #000000;
}
li a:hover {
background-color: #0cf72a;
}
.word-container {
width: 500px;
height: 50px;
margin: auto;
position: relative;
top: 80px;
}
.word-container h1 {
margin: 0;
text-align: center;
color: #ab0a0a;
}
.register-container {
width: 600px;
height: 350px;
margin: auto;
position: relative;
top: 100px;
border: 1px solid #000;
}
.fname input[type="text"] {
position: relative;
left: 115px;
top: 30px;
padding: 8px;
}
.lname input[type="text"] {
position: relative;
left: 314px;
top: -5.5px;
padding: 8px;
}
.userid input[type="text"] {
position: relative;
left: 115px;
padding: 8px;
top: 10px;
}
.pwd input[type="password"] {
position: relative;
padding: 8px;
left: 115px;
top: 25px;
}
.email input[type="email"] {
position: relative;
padding: 8px;
left: 115px;
top: 40px;
}
.btn button[type="submit"] {
position: relative;
left: 115px;
top: 55px;
padding: 8px;
width: 382px;
border: 1px solid #000000;
color: #ffffff;
background-color: #ab0a0a;
}
div.btn button[type="submit"]:hover {
background-color: rgb(255, 0, 0);
}
<div class="word-container">
<h1>Create your account</h1>
</div>
<div class="register-container">
<form action="" method="POST">
<div class="fname">
<label>
<input type="text" placeholder="First Name" name="fname" size="20">
</label>
</div>
<div class="lname">
<label>
<input type="text" placeholder="Last Name" name="lname" size="20">
</label>
</div>
<div class="userid">
<label>
<input type="text" placeholder="Username" name="userid" size="50">
</label>
</div>
<div class="pwd">
<label>
<input type="password" placeholder="Password" name="pwd" size="50">
</label>
</div>
<div class="email">
<label>
<input type="email" placeholder="Email Address" name="email" size="50">
</label>
</div>
<div class="btn">
<button type="submit">Create Account</button>
</div>
</form>
</div>
It's always a good idea to use something like normalize.css or any other CSS reset code (eric meyer css reset is very popular too) to reset CSS across all browsers.
Any browser come with it's defaults values for padding's,margins,widths, heights etc...
I guess it won't be an 100% solution but it will defiantly will take you closer to what you're looking for.
Do not jump to position relative and absolute. If you are new to all this, I can understand it seems the most natural way to go about positioning elements; just using a top and left position and that's that. But this is not how you should do it on the web!
Below you can find how I would do it.
Matan G. is right in pointing out that a CSS reset/normalize is often used, and I do so myself as well. However, before you do that (and considering you're new) it would be wise to take a look at the code that I posted and see if it makes any sense to you. If not, ask.
It is important to note that you should avoid these things when possible:
setting a fixed width to text items such as headings, paragraphs, lists.
using relative/absolute positioning. They are very useful but only when necessary.
using too many divs/classes than actually needed. Don't overcrowd your HTML.
* {box-sizing: border-box;}
ul {
background-color: #000000;
}
li a:hover {
background-color: #0cf72a;
}
.word-container {
width: 500px;
height: 50px;
margin: 80px auto auto;
}
.word-container h1 {
margin: 0;
text-align: center;
color: #ab0a0a;
}
.register-container {
width: 600px;
margin: 20px auto auto;
border: 1px solid #000;
padding: 20px;
}
label {
display: block;
}
.name::after {
content: "";
display: table;
clear: both;
}
.name label:first-child {
margin-right: 20px;
}
.name label {
width: calc(100% / 2 - 10px);
float: left;
}
input, [type="submit"] {
padding: 8px;
margin-bottom: 20px;
width: 100%;
}
[type="submit"] {
border: 1px solid #000000;
color: #ffffff;
background-color: #ab0a0a;
margin: 0;
}
[type="submit"]:hover {
background-color: red;
}
<div class="word-container">
<h1>Create your account</h1>
</div>
<div class="register-container">
<form action="" method="POST">
<div class="name">
<label>
<input type="text" placeholder="First Name" name="fname">
</label>
<label>
<input type="text" placeholder="Last Name" name="lname">
</label>
</div>
<label>
<input type="text" placeholder="Username" name="userid">
</label>
<label>
<input type="password" placeholder="Password" name="pwd">
</label>
<label>
<input type="email" placeholder="Email Address" name="email">
</label>
<button type="submit">Create Account</button>
</form>
</div>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Forms</title>
<style>
.container{
width: 45%;
margin: auto;
}
.form-content{
margin: 40px;
}
.form-content input{
width: 100%;
}
label{
font-weight: bold;
}
input[type=text],[type=email],[type=tel],[type=date],[type=password]{
font-size: 16px;
border-radius: 5px;
background: #D9F1F7;
border: #000000;
padding: 10px;
}
input[type=submit]{
background: #4C63ED;
padding: 10px;
border: none;
border-radius: 5px;
font-size: 16px;
color: #fff;
cursor: pointer;
}
input[type=submit]:hover{
background: #330EEF;
font-weight: bold;
}
</style>
</head>
<body>
<div class = "container">
<form name="signup" method="get" action="">
<div class="form-content">
<label>First Name : </label>
<input type="text" name="firstname" />
</div>
<div class="form-content">
<label>Last Name : </label>
<input type="text" name="lastname" />
</div>
<div class="form-content">
<label>E-Mail : </label>
<input type="email" name="email" />
</div>
<div class="form-content">
<label>Telephone : </label>
<input type="tel" name="telephone" />
</div>
<div class="form-content">
<label>Date of Birth : </label>
<input type="date" name="dob" />
</div>
<div class="form-content">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
</div>
</body>
</html>

Issue getting a submit button to center in a wrap

For some reason I cannot get the submit button to center. I have tried everything from text-align: center; to margin: 0 auto; to a left and right margin at auto. The button will not center anyway I try. What am I failing to do?
.contactForm {
border: 2px solid black;
background-color: #F0F0F0;
width: 40%;
margin: 0 auto;
padding: 40px;
}
.contactButton {
margin-top: 15px;
margin-right: auto;
margin-bottom: 15px;
margin-left: auto;
width: 425px;
font-size: 20px;
font-weight: bold;
padding: 14px;
cursor: pointer;
background-color: #800000;
border: none;
color: #FFFFFF;
text-align: center;
}
<div class="contactForm">
<form action="" method="post" id="mycontactform">
<input type="text" class="inputbar" name="name" placeholder="Full Name" required>
<input type="email" class="inputbaremail" name="email" placeholder="Email" required>
<textarea rows="4" cols="50" name="message" class="inputbarmessage" placeholder="Message" required></textarea>
<label for="contactButton">
<input type="button" class="contactButton" value="Send Message" id="submit">
</label>
</form>
</div>
It's hard to center is, because it is inside a label. The label is an inline element too and will size around the button. Therefor text-align: center and other solutions don't work.
In the snippet below, I've made the label show itself as a block element, which automatically occupies the available width of the parent. Then you can easily center the button inside it:
The added piece:
label[for="contactButton"] {
display: block;
text-align: center;
}
The whole code:
.contactForm {
border: 2px solid black;
background-color: #F0F0F0;
width: 40%;
margin: 0 auto;
padding: 40px;
}
.contactButton {
margin-top: 15px;
margin-right: auto;
margin-bottom: 15px;
margin-left: auto;
width: 425px;
/* Make sure the button isn't too wide on small screens */
max-width: 80%;
font-size: 20px;
font-weight: bold;
padding: 14px;
cursor: pointer;
background-color: #800000;
border: none;
color: #FFFFFF;
text-align: center;
}
label[for="contactButton"] {
display: block;
text-align: center;
}
<div class="contactForm">
<form action="" method="post" id="mycontactform">
<input type="text" class="inputbar" name="name" placeholder="Full Name" required>
<input type="email" class="inputbaremail" name="email" placeholder="Email" required>
<textarea rows="4" cols="50" name="message" class="inputbarmessage" placeholder="Message" required></textarea>
<label for="contactButton">
<input type="button" class="contactButton" value="Send Message" id="submit">
</label>
</form>
</div>
Use text-align:center on the parent div.
Fiddle: http://jsfiddle.net/gopal/su3vg018/
.contactForm {
text-align:center;
}
Add this to your css file:
.contactForm label[for="contactButton"] {
display: block;
text-align: center;
}