CSS Contact Form not being responsive - html

I have created a Contact Form, everything looks somewhat fine, the way I want it but having issues. The Form is not being responsive when re-sizing/scale the browser down. I have messed around, I think a little too much with the code to the point that I have no clue what i'm doing or have done. I'm about to lose my mind!
When I re-size the browser, the labels go outside of the container it's in. The submit button is also not centering even when I try margin: 0 auto;
I will post the HTML & CSS along with my CodePen below. Thanks for any help!
CodePen https://codepen.io/vCoCo/pen/MLReKK?editors=1100
HTML
<section id="contact">
<div class="container">
<form id="contactForm" action="contactform.php" method="post">
<h2> Get In Touch! </h2>
<div class="details">
<label for="firstName"> First Name </label>
<input type="text" id="firstName" name="firstName" placeholder="Enter First Name..." required>
</div>
<div class="details">
<label for="lastName"> Last Name </label>
<input type="text" id="lastName" name="lastName" placeholder="Enter Last Name..." required>
</div>
<div class="details">
<label for="email"> Email </label>
<input type="email" id="email" name="email" placeholder="Enter Email..." required>
</div>
<div class="details">
<label for="textMessage"> Message </label>
<textarea id="textMessage" name="textMessage" placeholder="Enter Message In Here..." required></textarea>
</div>
<input type="submit" value="Submit Message">
</form>
</div>
</section>
CSS
body{
background-color: grey;
}
/**** GLOBAL ****/
.container{
max-width: 80%;
margin: auto;
overflow: hidden;
border: 2px solid white;
}
/********** CONTACT FORM **********/
#contact{
max-width: 80%;
margin: 100px auto;
border: 1px dashed orange;
}
#contact .container{
width: 500px;
margin: 100px auto;
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
#contactForm{
margin: 0 auto;
}
#contactForm h2{
text-align: center;
margin-bottom: 10px;
}
.details{
max-width: 500px;
margin: 15px;
padding: 10px;
border: solid 1px #ff0000;
overflow: hidden;
}
label{
margin-bottom: 10px;
}
input[type=text], input[type=email]{
width: 400px;
padding: 12px 20px;
margin: 8px 0;
border: 2px solid;
border-radius: 4px;
}
input[type=submit]{
width: 200px;
padding: 10px 20px;
color: #fff;
background-color: #000;
border: 2px solid #fff;
border-radius: 10px;
font-family: inherit;
cursor: pointer;
}
textarea{
width: 300px;
height: 200px;
resize: none;
font-size: 16px;
}
#contactForm textarea::placeholder{
font-size: 16px;
}

You have a problem with the width of several elements, you're setting fixed widths and it repercusses on mobile resolutions, also with the overflow of the container it make the childs to hide inside the parent.
A good solution for a responsive mode is to set the widths to 100% of the parent and setting a max width for greater resolutions.
I made a fork of your Codepen.
Important: most of the problem also is, make sure to set the box-sizing of global elements. i.e. * { box-sizing: border-box;}
Hope this helps.
Codepen https://codepen.io/devlumberjack/pen/rPbMzr?editors=1100

Related

placeholder disappears after changing margin between inputs

I have a form in a Landing Page. I just wanted to change the margin between inputs:
This is what I have now:
I want to achieve this result:
This is the code:
<input class="input-form-catalogue" type="text" name="name" placeholder="name*" required>
<input class="input-form-catalogue" type="email" name="email" placeholder="email*" required>
<div class="row">
<div class="col-6">
<select name="country" title="country*" class="select-country-form-catalogue selectpicker text-center">
#include('includes.options-country')
</select>
</div>
<div class="col-6" style="padding-right:7.5px;padding-left: 2px;">
<input class="input-form-catalogue" type="text" name="phone" placeholder="phone*" required>
</div>
</div>
These are the classes:
.input-form-catalogue {
width: 100%;
padding: 0.7rem;
border: 0.1px solid #7B7B79;
background: transparent;
margin: 1rem 0;
text-align: center;
}
.select-country-form-catalogue {
width: 100%;
padding: 0.55rem;
border: 0.1px solid #7B7B79;
background: transparent;
margin: 1rem 0;
text-align: center;
color: #7B7B79;
}
I just simply wanted to change the margin attribute on the css classes. So I changed them to:
margin: 0.5rem 0;
But after doing that the placeholders on the text input dissapear. I have no idea why:
Any suggestions? Thank you in advance.
I solved it by adding another class called "press" to each text input, then I changed the CSS to:
.input-form-catalogue.press {
width: 100%;
padding: 0.7rem;
border: 0.1px solid #7B7B79;
background: transparent;
margin: 0.5rem 0;
text-align: center;
}

Why does the writable part of the form start from the middle?

Basically I tried to make a form for the first time, but I can't manage to understand why the writable area doesn't start from the beginning. I think it might have something to do with the padding, but I'm not sure. I know that the answer will probably be obvious, but I'm pretty new to this enviroment and to be honest I can't figure it out. Obviously there isn't all of the code of the website, I just posted the interested part.Thank you in advance.
label{
font-size: 30px;
font-family: 'Raleway', sans-serif;
margin-left: -390px;
margin-right: 100px;
display: block;
margin-top: 70px;
}
input[type=text],
input[type=email],
textarea{
padding: 12px 200px;
box-sizing: border-box;
background-color: #222326;
border: none;
border-bottom: 1px solid #D9D9D9;
text-align: left;
}
.msg-label{
margin-left: -345px;
}
.email-label{
margin-left: -398px;
}
textarea{
margin-bottom: 100px;
padding-right: 300px 220px;
overflow:hidden;
margin-right: -50px;
}
<div id="contact-me">
<div id="center">
<h2>CONTACT ME</h2>
</div>
<div id="center">
<form action="action-page.php">
<label for="name" class="name-label">Name</label>
<input type="text" id="name" name="full-name" >
<label for="email" class="email-label">Email</label>
<input type="email" id="email" name="email">
<label for="message" class="msg-label">Message</label>
<textarea id="msg" name="message"></textarea>
<input type="submit" value="Submit">
</form>
</div>
</div>
input[type=text],
input[type=email],
textarea{
padding: 12px 200px;
box-sizing: border-box;
background-color: #222326;
border: none;
border-bottom: 1px solid #D9D9D9;
text-align: left;
}
its the padding that you have added in the snippet above. padding adds space within the element as such you are pushing everything inside.

Seperate input boxes on the same line - Flexbox

I've created a contact form in figma that I'm trying to recreate using Flexbox. The form consists of 4 inputs which are "Name", "Phone", "Email" and "Message.
The name field is 828px wide. Phone and email fields are 406px wide.
I want the phone and email fields on the same row with 16px margin between them. On the next row will be the message field that is 828px wide.
The form is inside a container that is 828px wide with display set to flex.
How can I put the phone and email on the same row? I've attached a screen shot to show how my form currently looks. P.S I know there's redundent code in terms of styling. I'll clean it up later.
.form {
margin: 75px auto;
max-width: 828px;
display: flex;
}
.home-name {
background: #ffffff;
border: 1px solid #eaeaea;
width: 828px;
height: 38px;
padding: 14px auto;
}
.home-phone {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 406px;
height: 38px;
}
.home-email {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 406px;
height: 38px;
}
.home-message {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 828px;
height: 167px;
}
<html>
<head>
<body>
<div class="form">
<div>
<div class="name-form">
<input type="text" placeholder="Name" class="home-name" required>
</div>
<div class="phone-form">
<input type="text" placeholder="Phone" class="home-phone" required>
</div>
<div class="email-form">
<input type="text" placeholder="Email" class="home-email" required>
</div>
<div class="message-form">
<textarea placeholder="Message" class="home-message" required></textarea>
</div>
<button class="home-message-contact" type="submit">Submit</button>
</form>
</div>
</html>
</head>
</body>
Please check the code below for details change. I added flex-wrap: wrap; and change max-width: 828px; to width: 828px; on class .form. I cleaned up the HTML code by removing one unnecessary <div>.
.form {
margin: 75px auto;
width: 828px;
display: flex;
flex-wrap: wrap;
}
.home-name {
background: #ffffff;
border: 1px solid #eaeaea;
width: 828px;
height: 38px;
padding: 14px auto;
}
.home-phone {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 406px;
height: 38px;
}
.home-email {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 406px;
height: 38px;
}
.home-message {
background: #ffffff;
border: 1px solid #eaeaea;
box-sizing: border-box;
width: 828px;
height: 167px;
}
<div class="form">
<div class="name-form">
<input type="text" placeholder="Name" class="home-name" required>
</div>
<div class="phone-form">
<input type="text" placeholder="Phone" class="home-phone" required>
</div>
<div class="email-form">
<input type="text" placeholder="Email" class="home-email" required>
</div>
<div class="message-form">
<textarea placeholder="Message" class="home-message" required></textarea>
</div>
<button class="home-message-contact" type="submit">Submit</button>
</div>
just add these code to your style
.phone-form ,.email-form{
float:left;
}
.email-form{
margin-left: 12px;
}

I can't alter the width of an item through CSS

I'm a beginner in front-end development and I'm working on a survey website. My website has a lot of input fields and I want to alter their width per their nature but I'm not able to do it for some reason. The item is not in a flex container and yet changing the value in the width attribute makes no difference.
I'm trying to change the width of my input field in my customerAge div to make it small enough to just hold 2 digits.
This is my codepen link: https://codepen.io/omaroz92/full/VBWbae/
I'd appreciate a detailed explanation on why changing the value in the width attribute made no difference.
body {
background-color: #98AFC7;
}
#title {
text-align: center;
font-family: Arial, Times, serif;
font-style: oblique;
color: white;
}
#screen-belly {
background-color: rgb(250, 250, 250);
margin: 0 auto;
border-radius: 4px;
width: 75%;
max-width: 1000px;
padding: 10px;
padding-top: 20px;
}
p {
text-align: center;
font-family: monospace, serif;
font-size: 15px;
}
.container {
width: 75%;
max-width: 600px;
margin: 0 auto;
}
.row {
display: flex;
}
.customerAge {
width: 100px;
}
input {
flex: 1;
height: 20px;
min-width: 0;
padding: 5px;
margin: 10px;
border: 1px solid #c0c0c0;
border-radius: 2px;
}
<h1 id="title">Survey Form</h1>
<div id="screen-belly">
<p>Please take the short Survey to hep us improve our services</p>
<div class="container">
<div class="row">
<input autofocus type="text" name="name" id="name" placeholder="First name" required>
<input type="text" name="name" id="name" placeholder="Last Name" required>
</div>
<div class="row">
<input type="text" name="email" id="email" placeholder="e-Mail address" required>
</div>
<div class="customerAge">
<input type="number" name="age" id="Age" placeholder="age" required>
</div>
</div>
</div>
You've wrapped the Age input in customerAge div. But you've applied the width property to the parent, not to the input.
You can try this in your css code:
.customerAge input#Age {
width: 31px;
}
And you can change 31px to the value you want.
If you are confused, the input#Age after .customerAge, means: the input field with Age id that is inside of the customerAge class.

Form Input element sizing

I want to make a two column layout form. but I am getting a problem i.e input elements of form are not equally divided in size(width) and also responsive.
I want it to be responsive and also equally width with gap between them.
Attached Code Below
#import url('https://fonts.googleapis.com/css?family=Montserrat');
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
input[type="text"]{
display: block;
height: 30px;
width: 47%;
float:left;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
Try This
<form>
<div class="col-sm-6 col-xs-12 form-group">
<input type="text" name="" class="form-control">
</div>
<div class="col-sm-6 col-xs-12 form-group">
<input type="email" name="" class="form-control">
</div>
<div class="col-sm-12 form-group">
<textarea name="" cols="" rows="10" class="form-control"></textarea>
</div>
<form>
Just add this to your form section and also add the required files for botstrap
1- Jquery
2- Bootsrap.min.css
Bootsrap Documentation
JS fiddle
Remove float for inputs and add a wrapper div as below
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
#email{
display: block;
height: 30px;
width: 30%;
float:left;
margin:0;
margin-left:2%;
}
#name{
display: block;
height: 30px;
width: 30%;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section>
<form>
<h2>Contact Us</h2>
<div style="display: flex; justify-content: space-between;">
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
</div>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
If possible use Bootstrap with Grids, if not easy solution will be add div like this:
Bootstrap Grid LinK: https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
<form>
<h2>Contact Us</h2>
<div>
<input type="text" placeholder="Name">
</div>
<div>
<input type="text" placeholder="E-mail">
</div>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
Your selector form > input:nth-child(3) is a problem because it counts the h2 as the first, making the email-input the third and adding left-margin to it.
Once that is gone, I added margin: 30px 0; to the existing input['text'] selector, to match what you had applied to the textarea, and you may want different values, but everything is lined up and evenly spaced:
JS Fiddle
Example :
h2 {
font-family: Montserrat;
font-size: 3em;
line-height:50px;;
}
form {
width:70%;
margin: 10% auto;
}
#email{
display: block;
height: 30px;
width: 30%;
float:left;
margin:0;
margin-left:2%;
}
#name{
display: block;
height: 30px;
width: 30%;
float:left;
}
form > input:nth-child(3){
margin-left: 31px;
margin-right:0;
}
textarea {
width:100%;
box-sizing: border-box;
margin: 30px 0;
}
input[placeholder="Name"],input[placeholder="E-mail"]{
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
}
textarea[placeholder="Message"]{
letter-spacing:5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,textarea:focus {
outline:none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name" id='name'>
<input type="text" placeholder="E-mail" id='email'>
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>
Well ! i tried to figure out your problem and just gave a try to make it responsive.
Max-width and Max-height
The max-width property is used to set the maximum width of an element.
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of the containing block, or set to none (this is default. Means that there is no maximum width).
Using max-width instead, in this situation, will improve the browser's handling of small windows. similarly for height
You can remove margin: 0 auto; if you want don't want your content centred
#import url('https://fonts.googleapis.com/css?family=Montserrat');
h2 {
white-space: auto;
font-family: Montserrat;
font-size: 3em;
line-height: 50px;
;
}
form {
width: 70%;
margin: 0 auto;
}
input[type="text"] {
max-height: 30px;
max-width: 47%;
}
textarea {
max-width: 100%;
box-sizing: border-box;
margin: 10px 0;
}
input[placeholder="Name"],
input[placeholder="E-mail"] {
padding: 10px;
letter-spacing: 5px;
font-family: Montserrat;
margin-bottom: 10px;
}
textarea[placeholder="Message"] {
letter-spacing: 5px;
padding: 10px;
font-family: Montserrat;
}
/*
input , textarea {
border-width: 0 0 2px 0;
border-color: #000;
}*/
form input,
textarea:focus {
outline: none;
}
<section id="contact-page">
<form>
<h2>Contact Us</h2>
<input type="text" placeholder="Name">
<input type="text" placeholder="E-mail">
<textarea name="message" placeholder="Message" rows="6"></textarea>
</form>
</section>