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;
}
Related
I want the the input box of class message to be of 50px of height but it is not increasing even though i have added padding to it (refer the last part of css code) . All are coming of the same length. Please help me with this one .Any help would be appreciated.
HTML code
<section class="contact">
<h3>
Contact Us
</h3>
<div class="form">
<input type="text" class="name" id="name" placeholder="Enter Your name" />
<input type="text" class="name" id="name" placeholder="Enter Your phone" />
<input type="email" class="name" id="name" placeholder="Enter Your email" />
<input type="text" class="message" id="message" placeholder="Enter Your message" />
</div>
</section>
CSS code
* {
box-sizing: border-box;
}
.contact {
background-color: rgb(233, 230, 227);
height: 100%;
}
.contact h3 {
text-align: center;
}
.form {
text-align: center;
max-width: 344px;
width: 100%;
position: relative;
left: 50%;
transform: translatex(-50%);
}
.form input {
width: 100%;
padding: 7px;
border: 1px solid grey;
border-radius: 5px;
margin: 15px 0px;
}
.form message {
padding: 50px;
}
You forgot to add a . to this .form message.
* {
box-sizing: border-box;
}
.contact {
background-color: rgb(233, 230, 227);
height: 100%;
}
.contact h3 {
text-align: center;
}
.form {
text-align: center;
max-width: 344px;
width: 100%;
position: relative;
left: 50%;
transform: translatex(-50%);
}
.form input {
width: 100%;
padding: 7px;
border: 1px solid grey;
border-radius: 5px;
margin: 15px 0px;
}
.form .message {
padding: 50px;
}
<section class="contact">
<h3>
Contact Us
</h3>
<div class="form">
<input type="text" class="name" id="name" placeholder="Enter Your name" />
<input type="text" class="name" id="name" placeholder="Enter Your phone" />
<input type="email" class="name" id="name" placeholder="Enter Your email" />
<input type="text" class="message" id="message" placeholder="Enter Your message" />
</div>
</section>
please check complete code :
* {
box-sizing: border-box;
}
.contact {
background-color: rgb(233, 230, 227);
height: 100%;
}
.contact h3 {
text-align: center;
}
.form {
text-align: center;
max-width: 344px;
width: 100%;
position: relative;
left: 50%;
transform: translatex(-50%);
}
.form input {
width: 100%;
padding: 7px;
border: 1px solid grey;
border-radius: 5px;
margin: 15px 0px;
}
.form textarea {
resize:none;
width:100%;
border-radius: 5px;
padding: 7px;
}
<section class="contact">
<h3>
Contact Us
</h3>
<div class="form">
<input type="text" class="name" id="name" placeholder="Enter Your name">
<input type="text" class="name" id="name" placeholder="Enter Your phone">
<input type="email" class="name" id="name" placeholder="Enter Your email">
<textarea rows="4" placeholder="Enter Your message"></textarea>
</div>
</section>
Also, you can use textarea tag like this
<textarea rows="4" cols="50">Enter your message here </textarea>
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>
I have these fields in a search form …
<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get"><input name="utf8" type="hidden" value="✓">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="searchField">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="searchField">
<input type="text" name="event" id="event" placeholder="Event" class="searchField">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>
then I have this style for the form …
#search-form {
display: flex;
flex: 1 0 auto;
}
Problem is, the elements appear right next to each other — https://jsfiddle.net/fmy1syfw/ . I would like at least a pixel of space between them to not make everything seem so cramped. I have tried adding
margin: 1px;
to the above style, but to no avail. How do I add a pixel of space between my elements without breaking the behavior of the form at different screen widths?
Just add margin as required to the inputs and remove it in your media queries (again, as required).
Since you have used fixed widths of 50% in you media query, these will have to be adjusted using calc to account for the extra margin.
body {
background-color: grey;
}
#logo {
margin: 0 auto;
padding: 10px;
}
#searchForm {
padding: 20px;
}
#search-form {
background-color: orange;
display: flex;
flex: 1 0 auto;
}
#last_name,
#event {
margin-left: 1px;
}
#first_name,
#last_name {
width: 20%;
}
#event {
flex-grow: 1;
}
/* Do not specify width to allow it to grow freely */
.search_button {
width: 40px;
height: 40px;
}
/* Predefine image dimensions to ensure proper aspect ratio */
#loginArea {
border-radius: 25px;
font-size: 20px;
padding: 20px;
background-color: #ffffff;
color: #000000;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
width: 100%;
max-width: 580px;
}
#media (max-width: 620px) {
#search-form {
flex-wrap: wrap;
}
#first_name {
width: 50%;
margin: 0;
}
#last_name {
width: calc(50% - 1px);
margin-left: 1px;
}
#event {
width: calc(100% - 40px);
margin: 0;
}
}
.searchField {
line-height: 40px;
font-size: 22px;
margin: 0;
padding: 5px;
border: 1px solid #ccc;
box-sizing: border-box;
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
-webkit-user-select: text;
letter-spacing: normal;
word-spacing: normal;
text-transform: none;
text-indent: 0px;
text-shadow: none;
text-align: start;
}
<div id="loginArea">
<div id="searchForm">
Search For Results
<br />
<div>
<form id="search-form" action="/events/search" accept-charset="UTF-8" method="get">
<input name="utf8" type="hidden" value="✓">
<input type="text" name="first_name" id="first_name" placeholder="First Name" class="searchField">
<input type="text" name="last_name" id="last_name" placeholder="Last Name" class="searchField">
<input type="text" name="event" id="event" placeholder="Event" class="searchField">
<input alt="Search" type="image" src="http://www.racertracks.com/assets/magnifying-glass-0220f37269f90a370c3bb60229240f2ef2a4e15b335cd42e64563ba65e4f22e4.png" class="search_button">
</form>
</div>
</div>
</div>
JSFiddle Demo
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">
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>