css - How can I center my html form? -
so watched tutorial on how create contact me form. problem having trouble centering it. uses grid tags , responsive. keep responsive there when in full width want centered logo is. (new html & css 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 passes 700px */ @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 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 passes 700px */ @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 use margin: auto
, might stumble upon weird behaviors if use grid somewhere not shown in code.
further reading:
wiki
Comments
Post a Comment