How can I center my html form? - html

So I watched this tutorial on how to create a good contact me form. But the problem is I am having trouble centering it. It uses some grid tags and it responsive. So I would like to keep the responsive there but when in full width I want it to be centered like the logo is. (New to HTML & CSS just learning)
HTML Code
<div class="container">
<h1 class="brand"><span>Acme</span> Web Design</h1>
<div class="wrapper animated bounceInLeft">
<div class="contact">
<h3>Email Us</h3>
<form>
<p>
<label>Name</label>
<input type="text" name="name">
</p>
<p>
<label>Company</label>
<input type="text" name="company">
</p>
<p>
<label>Email Address</label>
<input type="email" name="email">
</p>
<p>
<label>Phone Number</label>
<input type="text" name="phone">
</p>
<p class="full">
<label>Message</label>
<textarea name="message" rows="5"></textarea>
</p>
<p class="full">
<button>Submit</button>
</p>
</form>
</div>
</div>
My CSS
*{
box-sizing: border-box;
}
body{
background:#92bde7;
color:#485e74;
line-height:1.6;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding:1em;
}
.container{
max-width:1170px;
margin-left:auto;
margin-right:auto;
padding:1em;
}
ul{
list-style: none;
padding:0;
}
.brand{
text-align: center;
}
.brand span{
color:#fff;
}
/* REMOVE */
/*
.wrapper{
box-shadow: 0 0 20px 0 rgba(72,94,116,0.7);
}
*/
.wrapper > *{
padding: 1em;
}
/* REMOVE */
/*
.company-info{
background:#DA00F0;
}
*/
/*
.company-info h3, .company-info ul{
text-align: center;
margin:0 0 1rem 0;
}
*/
.contact{
background:#f9feff;
}
/* FORM STYLES */
.contact form{
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap:20px;
}
.contact form label{
display:block;
}
.contact form p{
margin:0;
}
.contact form .full{
grid-column: 1 / 3;
}
.contact form button, .contact form input, .contact form textarea{
width:100%;
padding:1em;
border:1px solid #c9e6ff;
}
.contact form button{
background:#c9e6ff;
border:0;
text-transform: uppercase;
}
.contact form button:hover,.contact form button:focus{
background:#92bde7;
color:#fff;
outline:0;
transition: background-color 2s ease-out;
}
/* LARGE SCREENS */
/*Once it passes 700px do this */
#media(min-width:700px){
.wrapper{
display: grid;
grid-template-columns: 1fr 2fr;
}
.wrapper > *{
padding:2em;
}
.brand .contact{
text-align: center;
}
}

#media(min-width: 700px){
.wrapper {
/* remove this
display: grid;
grid-template-columns: 1fr; */
display: flex;
justify-content: center;
}
*{
box-sizing: border-box;
}
body{
background:#92bde7;
color:#485e74;
line-height:1.6;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding:1em;
}
.container{
max-width:1170px;
margin-left:auto;
margin-right:auto;
padding:1em;
}
ul{
list-style: none;
padding:0;
}
.brand{
text-align: center;
}
.brand span{
color:#fff;
}
/* REMOVE */
/*
.wrapper{
box-shadow: 0 0 20px 0 rgba(72,94,116,0.7);
}
*/
.wrapper > *{
padding: 1em;
}
/* REMOVE */
/*
.company-info{
background:#DA00F0;
}
*/
/*
.company-info h3, .company-info ul{
text-align: center;
margin:0 0 1rem 0;
}
*/
.contact{
background:#f9feff;
}
/* FORM STYLES */
.contact form{
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap:20px;
}
.contact form label{
display:block;
}
.contact form p{
margin:0;
}
.contact form .full{
grid-column: 1 / 3;
}
.contact form button, .contact form input, .contact form textarea{
width:100%;
padding:1em;
border:1px solid #c9e6ff;
}
.contact form button{
background:#c9e6ff;
border:0;
text-transform: uppercase;
}
.contact form button:hover,.contact form button:focus{
background:#92bde7;
color:#fff;
outline:0;
transition: background-color 2s ease-out;
}
/* LARGE SCREENS */
/*Once it passes 700px do this */
#media(min-width:700px){
.wrapper{
display: flex;
justify-content: center;
}
.wrapper > *{
padding:2em;
}
.brand .contact{
text-align: center;
}
}
<div class="container">
<h1 class="brand"><span>Acme</span> Web Design</h1>
<div class="wrapper animated bounceInLeft">
<div class="contact">
<h3>Email Us</h3>
<form>
<p>
<label>Name</label>
<input type="text" name="name">
</p>
<p>
<label>Company</label>
<input type="text" name="company">
</p>
<p>
<label>Email Address</label>
<input type="email" name="email">
</p>
<p>
<label>Phone Number</label>
<input type="text" name="phone">
</p>
<p class="full">
<label>Message</label>
<textarea name="message" rows="5"></textarea>
</p>
<p class="full">
<button>Submit</button>
</p>
</form>
</div>
</div>
While you could use margin: auto, you might stumble upon weird behaviors if you use grid somewhere not shown in your code.
Further reading:
Css grid
A guide to css flexbox

This code could be of help, basically I have removed the code that is affecting the container of the form and added so that it will work in responsive in a single field.
CSS:
*{
box-sizing: border-box;
}
body{
background:#92bde7;
color:#485e74;
line-height:1.6;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding:1em;
}
.container{
max-width:1170px;
margin-left:auto;
margin-right:auto;
padding:1em;
}
ul{
list-style: none;
padding:0;
}
.brand{
text-align: center;
}
.brand span{
color:#fff;
}
/* REMOVE */
/*
.wrapper{
box-shadow: 0 0 20px 0 rgba(72,94,116,0.7);
}
*/
.wrapper > *{
padding: 1em;
}
/* REMOVE */
/*
.company-info{
background:#DA00F0;
}
*/
/*
.company-info h3, .company-info ul{
text-align: center;
margin:0 0 1rem 0;
}
*/
.contact{
background:#f9feff;
max-width: 680px;
margin: auto;
}
/* FORM STYLES */
.contact form{
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap:20px;
}
.contact form label{
display:block;
}
.contact form p{
margin:0;
}
.contact form .full{
grid-column: 1 / 3;
}
.contact form button, .contact form input, .contact form textarea{
width:100%;
padding:1em;
border:1px solid #c9e6ff;
}
.contact form button{
background:#c9e6ff;
border:0;
text-transform: uppercase;
}
.contact form button:hover,.contact form button:focus{
background:#92bde7;
color:#fff;
outline:0;
transition: background-color 2s ease-out;
}
#media screen and (max-width: 680px) {
.contact{
max-width: inherit;
}
.contact form {
display: block;
}
}
EXAMPLE: https://jsfiddle.net/8dvch6nj/

Depending on whether or not you wanted to keep the entire block in grid format, you could always change .wrapper to not use the grid, but just have a margin of 0px auto. If you wanted to still use grid layout, you could just change .wrapper to a width of 100%
*{
box-sizing: border-box;
}
body{
background:#92bde7;
color:#485e74;
line-height:1.6;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
padding:1em;
}
.container{
max-width:1170px;
margin-left:auto;
margin-right:auto;
padding:1em;
}
ul{
list-style: none;
padding:0;
}
.brand{
text-align: center;
}
.brand span{
color:#fff;
}
/* REMOVE */
/*
.wrapper{
box-shadow: 0 0 20px 0 rgba(72,94,116,0.7);
}
*/
.wrapper > *{
padding: 1em;
}
/* REMOVE */
/*
.company-info{
background:#DA00F0;
}
*/
/*
.company-info h3, .company-info ul{
text-align: center;
margin:0 0 1rem 0;
}
*/
.contact{
background:#f9feff;
}
/* FORM STYLES */
.contact form{
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap:20px;
}
.contact form label{
display:block;
}
.contact form p{
margin:0;
}
.contact form .full{
grid-column: 1 / 3;
}
.contact form button, .contact form input, .contact form textarea{
width:100%;
padding:1em;
border:1px solid #c9e6ff;
}
.contact form button{
background:#c9e6ff;
border:0;
text-transform: uppercase;
}
.contact form button:hover,.contact form button:focus{
background:#92bde7;
color:#fff;
outline:0;
transition: background-color 2s ease-out;
}
/* LARGE SCREENS */
/*Once it passes 700px do this */
#media(min-width:700px){
.wrapper{
display: grid;
grid-template-columns: 100%;
}
.wrapper > *{
padding:2em;
}
.brand .contact{
text-align: center;
}
}
<div class="container">
<h1 class="brand"><span>Acme</span> Web Design</h1>
<div class="wrapper animated bounceInLeft">
<div class="contact">
<h3>Email Us</h3>
<form>
<p>
<label>Name</label>
<input type="text" name="name">
</p>
<p>
<label>Company</label>
<input type="text" name="company">
</p>
<p>
<label>Email Address</label>
<input type="email" name="email">
</p>
<p>
<label>Phone Number</label>
<input type="text" name="phone">
</p>
<p class="full">
<label>Message</label>
<textarea name="message" rows="5"></textarea>
</p>
<p class="full">
<button>Submit</button>
</p>
</form>
</div>
</div>

Related

Center footer at the bottom of the page

I am trying to place a footer at the center bottom of my page. I have the following css and html but I can't figure out a good way of doing it. Currently the issue is that the footer falls outside of the screenview on loading. Hate that and I think it has to do with the fact that the footer has position:flex. But I set "absolute" it gets messed up (see 2nd picture).
css
body {
background-color: white;
margin-top:3em;
margin-bottom:3vw;
margin-left:12vw;
margin-right:12vw;
font-family:Georgia;
font-size:1em;
color: #4D4D4D;
}
hr {
margin-bottom:3vw;
margin-top:10px;
height:0.08em;
border-width:0;
color:#231F20;
background-color:#231F20;
opacity: 0.2
}
a:link {
color: #0168DA;
text-decoration: none;
font-size:1em;
}
ul {
font-family:Georgia;
}
h3 {
margin-block-end: 0em;
}
p {
margin-block-start: 0.5em;
margin-block-end: 0.5em;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
margin-bottom: 4em;
}
* {
box-sizing: border-box;
}
#media only screen and (min-device-width: 480px) {
body {
margin-left:17vw;
margin-right:17vw;
}
}
/* other */
.menu {
padding-top: 3em;
margin-bottom: 5em;
}
.right {
text-align: right;
}
/* footer */
.footer-basic {
padding:40px 0;
margin-top: 16em;
background-color:#ffffff;
color:#4b4c4d;
bottom: 10px;
text-align: center;
}
.footer-basic ul {
padding:0;
list-style:none;
text-align:center;
font-size:15px;
line-height:1.6;
margin-bottom:0;
}
.footer-basic li {
padding:0 10px;
}
.footer-basic ul a {
color:inherit;
text-decoration:none;
opacity:0.8;
}
.footer-basic ul a:hover {
opacity:1;
}
.footer-basic .copyright {
margin-top:15px;
text-align:center;
font-size:13px;
color:#aaa;
margin-bottom:0;
}
.list-inline {
list-style: none;
padding: 0;
}
.list-inline > li {
display: inline;
margin: 0;
}
html
html>
<head>
{% load static %}
</head>
<body>
<p align="center">
<span style="color:#B02E25;font-size:1.5em;">A Month At A Time</span>
</p>
<div>
<img width="150" height="94" src="https://res.cloudinary.com/giaggi/image/upload/v1613837471/amonthatatime/images/general/calvinandhobbes.png">
</div>
{% for post in latest_posts %}
<div class="post">
<h3> {{post.title | safe}}
<br> <span style="opacity:0.6; font-size:0.8em">{{post.month | safe}} {{post.year | safe}} </span>
</h3>
<p style="opacity: 0.7;"> {{post.whatsapp | safe | truncatewords:50 }} </p>
<div class="right">
<a style="color:#B02E25;" href="/amonthatatime/{{post.year}}/{{post.month}}/" target="">Open</a>
</div>
</div>
<hr>
{% endfor %}
<div style="position:flex; bottom:0.5em;">
<div class="footer-basic">
<footer>
<ul class="list-inline" style="margin:3px" >
<li class="list-inline-item"><a style="font-family:Georgia;color: #0168DA;" href="/amonthatatime/subscribe">Subscribe</a></li>
</ul>
<!-- <p class="copyright">A month at a Time</p> -->
</footer>
</div>
</div>
</body>
</html>
I hope's the result goes acording you're need's
You can use this, i just change the next CSS lines:
.footer-basic {
padding: 10px 0;
margin-top: 1em;
}
body {
background-color: white;
margin-top:3em;
margin-bottom:3vw;
margin-left:12vw;
margin-right:12vw;
font-family:Georgia;
font-size:1em;
color: #4D4D4D;
}
hr {
margin-bottom:3vw;
margin-top:10px;
height:0.08em;
border-width:0;
color:#231F20;
background-color:#231F20;
opacity: 0.2
}
a:link {
color: #0168DA;
text-decoration: none;
font-size:1em;
}
ul {
font-family:Georgia;
}
h3 {
margin-block-end: 0em;
}
p {
margin-block-start: 0.5em;
margin-block-end: 0.5em;
}
img {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 1em;
margin-bottom: 4em;
}
* {
box-sizing: border-box;
}
#media only screen and (min-device-width: 480px) {
body {
margin-left:17vw;
margin-right:17vw;
}
}
/* other */
.menu {
padding-top: 3em;
margin-bottom: 5em;
}
.right {
text-align: right;
}
/* footer */
.footer-basic {
padding: 10px 0;
margin-top: 1em;
background-color:#ffffff;
color:#4b4c4d;
bottom: 10px;
text-align: center;
}
.footer-basic ul {
padding:0;
list-style:none;
text-align:center;
font-size:15px;
line-height:1.6;
margin-bottom:0;
}
.footer-basic li {
padding:0 10px;
}
.footer-basic ul a {
color:inherit;
text-decoration:none;
opacity:0.8;
}
.footer-basic ul a:hover {
opacity:1;
}
.footer-basic .copyright {
margin-top:15px;
text-align:center;
font-size:13px;
color:#aaa;
margin-bottom:0;
}
.list-inline {
list-style: none;
padding: 0;
}
.list-inline > li {
display: inline;
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<p align="center">
<span style="color:#B02E25;font-size:1.5em;">A Month At A Time</span>
</p>
<div>
<img width="150" height="94"
src="https://res.cloudinary.com/giaggi/image/upload/v1613837471/amonthatatime/images/general/calvinandhobbes.png">
</div>
<div class="post">
<h3> {{post.title | safe}}
<br> <span style="opacity:0.6; font-size:0.8em">{{post.month | safe}} {{post.year | safe}} </span>
</h3>
<p style="opacity: 0.7;"> {{post.whatsapp | safe | truncatewords:50 }} </p>
<div class="right">
<a style="color:#B02E25;" href="/amonthatatime/{{post.year}}/{{post.month}}/" target="">Open</a>
</div>
</div>
<hr>
<div style="position:flex; bottom:0.5em;">
<div class="footer-basic">
<footer>
<ul class="list-inline" style="margin:3px">
<li class="list-inline-item"><a style="font-family:Georgia;color: #0168DA;"
href="/amonthatatime/subscribe">Subscribe</a></li>
</ul>
<!-- <p class="copyright">A month at a Time</p> -->
</footer>
</div>
</div>
</body>
</html>
So one way to achieve this, would be to add a fixed height to your footer and then a min-height to your content. Something like this:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
main {
min-height: calc(100vh - 4rem);
}
footer {
display: flex;
align-items: center;
justify-content: center;
height: 4rem;
}
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<main>
<p>Main content goes here</p>
</main>
<footer>
<p>Subscribe</p>
</footer>
</body>
</html>
This just relies on the main content filling up the majority of the page, and 'pushing' down the footer to the bottom. The major con with this method is that you need to set a height on your footer, which may or may not be fine for your needs - that way you can se the height of the main section to calc(100vh - 4rem) where 100vh is the the entire height of the page, less the height of your footer, in this example I made it 4rem (but you could make it whatever you like).
I didn't bother putting all your code in there, but I hope you can work it out from here.
Make sure to use min-height on your content, so that it can grow as you have more content.

Centering button in css

I am making a mock website as I learn to code and I cannot figure out how to center my "View my Work" button in CSS. I have looked at other issues people were having with this on Stack Overflow and I have tried wrapping it in a div and I have tried using input[type="button"] but still not getting anywhere.The second option allows me to move the button a little bit to the right but then stops and I can't get it all the way in the center.
The issue is at maximum screen width (#media screen and (min-width: 992px)).
A second issue I am having is that I want my background picture to have the opacity but not the heading and text in button on top of it. I do not know how to stop the opacity in the text. Thanks guys!
Here is the HTML:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css.css">
<title> Sankyeat Kumar | Web Developer </title>
</head>
<body>
<div id="menu">
<div>Home</div>
<div>Portfolio</div>
<div>Blog</div>
<div>Contact</div>
</div>
<div id="banner">
<div id="heading">
<h1> Sankyeat Kumar</h1>
<h4>London Based Web Developer For Hire</h4>
</div>
<div id="button">
<input type="button" value="View My Work" class="portfolio">
</div>
</div>
<div id="section-a">
<h2> Services </h2>
<div id="services">
<div class="sections">
<h3>Web Design</h3>
<p class="section-para">Freelance-Creator offers an exceptional variety of web design services to suit everybody, whether you're self employed or a small business, I can come up with a quality website to suit your needs. </p>
</div>
<div class="sections">
<h3>Responsive Web Sites </h3>
<p class="section-para">With everybody on the go with mobile & tablet devices it is important to make sure your website is accesible on the go. Responsive websites are also a cheaper alternative to a phone app! </p>
</div>
<div class="sections">
<h3>SEO & Marketing </h3>
<p class="section-para">SEO (Search Engine Optimisation) is important when it comes to creating an online presence for your website. We offer simple, cost effective and proven marketing results to all of our clients. </p>
</div>
<div class="sections">
<h3>CMS Solutions</h3>
<p class="section-para">Take full control of your website, whether it be a simple text modification, to an image upload or to adding 100's of products, we will find the right CMS solution for you, that is simple and user friendly. </p>
</div>
</div>
</div>
<div class="container">
<h2>Contact me</h2>
<form action="/action_page.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="country">Country</label>
<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
<label for="subject">Subject</label>
<textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
</div>
</body>
Here is the CSS:
body {
margin:0px;
padding:0px;
box-sizing: border-box;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#media screen and (min-width: 320px) {
#menu {
display:flex;
background-color: black;
max-height:50px;
max-width:100%;
}
#menu div {
margin: 0 auto;
color: ##678F99;
padding:10px;
}
#menu div a {
color:white;
text-decoration: none;
font-size: 1.5em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#menu div a:hover {
text-decoration: underline;
}
#banner {
height:100vh;
width:100%;
}
#heading {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
#banner #heading h1 {
color:black;
font-size: 4em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
text-align: center;
z-index: 1;
}
#banner #heading h4 {
color:black;
z-index: 1;
padding: 0 40px;
text-align: center;
font-size: 2em;
}
.portfolio {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 20px;
padding:10px;
background-color: black;
color: white;
border-radius: 4px;
position: relative;
left: 143px;
}
#heading h4 {
color: white;
font-size: 3em;
font-weight: normal;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
position: relative;
bottom:50px;
}
#section-a > h2 {
font-size: 40px;
display: flex;
align-items: center;
justify-content: center;
}
#section-a {
background-color: #5F5F5F;
}
#section-a h2 {
color:white;
}
#services {
display:flex;
flex-wrap: wrap;
color: white;
}
.sections {
padding: 0 20px;
}
.sections h3 {
text-align: center;
}
.section-para {
text-align: justify;
}
input[type=text], select, textarea {
width: 100%; /* Full width */
padding: 12px; /* Some padding */
border: 1px solid #ccc; /* Gray border */
border-radius: 4px; /* Rounded borders */
box-sizing: border-box; /* Make sure that padding and width stays in place */
margin-top: 6px; /* Add a top margin */
margin-bottom: 16px; /* Bottom margin */
resize: vertical /* Allow the user to vertically resize the textarea (not horizontally) */
}
/* Style the submit button with a specific background color etc */
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
/* When moving the mouse over the submit button, add a darker green color */
input[type=submit]:hover {
background-color: #45a049;
}
/* Add a background color and some padding around the form */
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
}
only screen and (min-width: 768px) {
}
#media screen and (min-width: 992px) {
#menu {
display:flex;
background-color: black;
max-height:50px;
max-width:100%;
}
#menu div {
margin: 0 auto;
color: ##678F99;
padding:10px;
}
#menu div a {
color:white;
text-decoration: none;
font-size: 1.5em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
#menu div a:hover {
text-decoration: underline;
}
#banner {
height:100vh;
width:100%;
background-image: url('images/london.jpg');
opacity: 0.5;
background-size: 100% 100%;
background-repeat: no-repeat;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
z-index: 0;
}
#heading {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
#banner #heading h1 {
color:black;
font-size: 5em;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: normal;
z-index: 1;
}
#banner #heading h4 {
color:black;
z-index: 1;
padding: 0 40px;
text-align: center;
}
.portfolio {
font-family: "Comic Sans MS", cursive, sans-serif;
font-size: 30px;
padding:10px;
background-color: black;
color: white;
border-radius: 4px;
display: flex;
justify-content: center;
}
input[type="button"] {
position:relative;
right:350px;
}
#heading h4 {
color: white;
font-size: 3em;
font-weight: normal;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
position: relative;
bottom:50px;
}
#section-a {
margin-top: -33px;
margin-bottom: 30px;
}
#section-a > h2 {
font-size: 40px;
display: flex;
align-items: center;
justify-content: center;
padding-top: 100px;
}
#services {
display:flex;
flex-wrap: nowrap;
margin-bottom: 80px;
}
.sections {
padding: 0 20px;
margin-bottom: 150px;
}
.sections h3 {
text-align: center;
}
.section-para {
text-align: justify;
}
.container {
margin-top: -80px;
}
input[type=text], select, textarea {
width: 100%; /* Full width */
padding: 12px; /* Some padding */
border: 1px solid #ccc; /* Gray border */
border-radius: 4px; /* Rounded borders */
box-sizing: border-box; /* Make sure that padding and width stays in
place */
margin-top: 6px; /* Add a top margin */
margin-bottom: 16px; /* Bottom margin */
resize: vertical /* Allow the user to vertically resize the textarea
(not horizontally) */
}
/* Style the submit button with a specific background color etc */
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
/* When moving the mouse over the submit button, add a darker green color */
input[type=submit]:hover {
background-color: #45a049;
}
/* Add a background color and some padding around the form */
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
}
you should try setting the following property for the button
display:inline-block;
position:static
margin-auto;
and don't forget to set it's parent width to 100%;
Hope It Helps

Contact form width issue

My contact form is looking how it is supposed to in desktop and tablet mode. However, when I switch my browser to mobile the email input in slightly shorter than the name input and the text box. What is causing this issue?
#formsec{
margin-left:20px;
margin-right:20px;
}
#worktogether{
text-align: center;
color:white;
font-size:50px;
margin-top:60px;
font-family: 'Philosopher', sans-serif;
}
form {
max-width:1200px;
margin: 0 auto 50px;
}
input, textarea {
border: 3px solid #69EAF5;
width:100%;
box-sizing:border-box;
padding:10px;
}
label{
display:block;
margin-bottom:20px;
}
span{
display:block;
color:white;
font-size:20px;
}
.contact-info-group label{
width: 50%;
box-sizing: border-box;
float:left;
}
.contact-info-group label:nth-child(1){
}
.contact-info-group label:nth-child(2){
padding-left:15px;
}
input:focus, textarea:focus{
outline: none;
border-color:#008a91;
}
textarea{
height:400px;
}
.button-wrap{
margin-left:67%;
width:33%;
}
[type="submit"]{
background:#097784;
border-color:#097784;
color:white;
font-size: 18px;
text-transform: uppercase;
}
#media screen and (max-width:480px){
.contact-info-group label{
width: 100%;
box-sizing: border-box;
float:left;
}
}
<section id="formsec">
<h3 id="worktogether">Let's Work Together</h3>
<form id="form2" action="FormToEmail.php" methods="POST">
<div class="contact-info-group">
<label><span>Your Name</span>
<input type="text" name="text"></label>
<label><span>Your Email</span>
<input type="email" name="_replyto"></label>
</div>
<label><span>How Can I Help:</span>
<textarea name="message"></textarea></label>
<input class="button-wrap" name="submit_to_programmer" type="submit" value="Submit"/>
</form></section>
You have 15px padding for desktop, which needs to be removed for mobile.
#media screen and (max-width:480px){
.contact-info-group label:nth-child(2) {
padding-left:0px;
}
}
You'll have to override the padding set for the second child in media query
#media screen and (max-width: 480px) {
.contact-info-group label:nth-child(2) {
padding-left: 0;
}
}

Center A form HTML CSS

Hello I am having issues centering a form for a login page. I am not to good with CSS and it has been a while since I have played with HTML. What I want to do is, center the input boxes and align the text left on top of the input fields, as well as have an image centered as well, like in the picture. I have tried adding different div id and tags to the form but I can not seem to figure out the css part. I appreciate any help and sorry if the CSS is sloppy.
body {
background-color:lightgray;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
h1 {
color: black;
}
p {
color: black;
}
html {
text-alight: center;
}
#login {
text-align:center;
}
input[type=text], input[type=date], input[type=password] {
width: 30%;
height: 50px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit] {
width: 30%;
height: 50px;
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
#service_type, #series, #speaker, #users {
width: 30%;
height: 50px;
}
#media only screen and (max-device-width: 1024px){
input[type=text], input[type=date], input[type=password] {
width: 100%;
height: 50px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
height: 50px;
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
#service_type, #series, #speaker, #users{
width: 100%;
height: 50px;
}
#keypad_users{
width: 345px;
height: 50px;
vertical-align:middle;
text-align:center;
border:1px solid #000000;
font-size:30px;
font-weight:bold;
}
#keypad {margin:auto; margin-top:10px;}
#keypad tr td {
vertical-align:middle;
text-align:center;
border:1px solid #000000;
font-size:18px;
font-weight:bold;
width:100px;
height:80px;
cursor:pointer;
background-color:#666666;
color:#CCCCCC;
}
#keypad tr td:hover {
background-color:#999999;
color:#FFFF00;
}
#display {
text-align:center;
width:345px;
margin:10px auto auto auto;
background-color:#000000;
color:#00FF00;
font-size:48px;
border:1px solid #999999;
}
#message {
text-align:center;
color:#009900;
font-size:18px;
font-weight:bold;
display:none;
}
}
<div id="login">
<form action = "login.php" id="login" method ="POST">
Username <br />
<input type="text" name="username" id="username" required /><br /><br />
Password <br />
<input type ="password" name="password" id="password" required /><br /><br />
<input type="submit" name="submit" value="Log in">
</form>
</div>
I've made a JSfiddle for you here (click me please) that resembles the picture you've added.
As requested to not use a third party like I've added the code here:
HTML
<div id="login">
<form action = "login.php" id="login" method ="POST">
<div class="picture">
</div>
<p>Username</p>
<input type="text" name="username" id="username" required /><br /><br />
<p>Password</p>
<input type ="password" name="password" id="password" required /><br /><br />
<input type="submit" name="submit" value="Log in">
</form>
</div>
CSS
body
{
background-color:lightgray;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
#login
{
text-align:center;
width: 50%;
margin: 0 auto;
}
.picture
{
width:100px;
height: 100px;
border-radius: 100px;
background-color:red;
margin: 0 auto;
}
#login p
{
float: left;
}
input[type=text], input[type=date], input[type=password] {
width: 100%;
height: 50px;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
height: 50px;
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
EDIT:
New fiddle here: https://jsfiddle.net/gay1ufa1/2/
I've improved your HTML. All form inputs should have an associated label element. Also don't use br for spacing use padding/margin instead.
Further more use have a duplicated id, id's must be unique to the page.
#login_container /*This is Our base container for the login "control" */
{
width:30%; /*Define the width of the control*/
margin:auto; /*This Provide the horizontal centering of the control*/
padding:120px 10px 10px 10px; /*Add some padding, the first number is the top and provides room for the image*/
background-image:url(" http://fillmurray.com/100/100"); /*Add our background image, thanks Bill Murray*/
background-position:center 10px; /*Position our image, first is Horizontal alignment, second is top*/
background-repeat:no-repeat; /*One Bil Murray is more than enough*/
background-color: #F0F0F0; /*Base Background image*/
}
#login_container label
{
display:block; /*Label will now take up a whole line*/
margin-bottom:.25em; /*Give it some room underneath*/
}
#login_container input[type="text"], #login_container input[type="password"], #login_container input[type="submit"]
{
width:100%; /*Form controls now take 100% width of the container*/
margin-bottom:0.5em;
}
<div id="login_container"> <!-- Can't have duplicate ID's -->
<form action = "login.php" id="login" method ="POST">
<label for="username">Username </label>
<input type="text" name="username" id="username" required />
<label for="password">Password</label>
<input type ="password" name="password" id="password" required />
<input type="submit" name="submit" value="Log in">
</form>
</div>
One problem in your code is that you use the ID "login " twice, which must not be done. I put together a codepen, which you can find here:
http://codepen.io/anon/pen/dNWQgp
What I basically did (except adding a div representing the image in your picture): I assigned the following CSS to a wrapper DIV around the whole form and image. It uses flexbox to center the contents. Plus I assigned a width setting (40%) to the form element.
.wrapper {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
To center a div set margin-left and margin-right to auto and assign a fixed width to it. In your case, this would be for #login.

Place two form elements inline

I currently have 1 form with 2 elements inside it (an email input and a submit button). This form looks like this for me:
But some of my associates seem to have it looking like this:
My relevant HTML looks like this:
<header>
<div class="wrap nopad">
<h1>Share and Listen to Music.</h1>
<form>
<input type="email" placeholder="Email address to get started"><input type="submit" value="Get Started">
</form>
</div>
</header>
and the relevant CSS looks like this:
body {
background-color: #1B1B1E;
color: #fff;
margin:0;
padding: 0;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
.wrap {
width:685px;
padding:0 15px;
margin:0 auto;
display: block;
}
.wrap.nopad {
width:700px;
padding: 0;
}
header {
width:100%;
padding:200px 0 100px;
background-color: #2de6c0;
display: block;
}
header .wrap h1 {
color:#000;
text-align: center;
display: block;
font-weight:bolder;
text-transform: uppercase;
font-size:45.4px;
letter-spacing: 0px;
}
header .wrap h1 span {
text-decoration: underline;
}
header form {
padding:20px 0 0;
width:660px;
margin:0 auto;
}
input[type=email] {
color:#000;
padding:20px;
display: inline-block;
outline: 0;
border: 0;
width:470px;
text-transform: uppercase;
font-size:24px;
font-weight: 500;
}
input[type=submit] {
background-color: #000;
color:#FFF;
text-transform:uppercase;
font-size:16px;
padding:25px 20px;
display: inline-block;
font-weight:500;
outline: 0;
border: 0;
cursor: pointer;
float: right;
}
Could you please point me in the right direction so I can fix my code to work in all browsers and be inline.
Thanks!
Fiddle
Reduce the padding of black submit button button.
input[type=submit]
{
padding: 25px 16px;
}
See the Demo
Demo2
It ll give you best design
input email button --> Width:71.4%
submit button ---> Remove left and right padding and add width 22.54%