html forms responsive in mobile view? - html

I have a form coded like this I want to make it responsive in both mobile and tablet version or responsive regardless:
</div>
<div class="contact_form">
<form
class="form"
action="https://sheetdb.io/api/v1/it1l3r9npizts"
method="post"
id="sheetdb-form"
>
<label for="name">Name:</label>
<input
type="text"
id="name"
name="data[name]"
placeholder="Your name"
/>
<label for="email">Email:</label>
<input
type="email"
id="email"
name="data[email]"
placeholder="Your email"
/>
<label for="message">Message:</label>
<textarea
id="message"
placeholder="Your message"
rows="6"
name="data[message]"
></textarea>
<div class="center">
<input type="submit" value="Send Message" />
</div>
</form>
</div>
with these styles in css:
.contact_section {
width: 100%;
height: 100%;
}
.contact_form {
display: flex;
align-items: center;
flex-direction: column;
}
.contact_form label {
margin: 15px 0;
}
.contact_form label {
font-size: 20px;
font-weight: 400;
}
.contact_form input,
textarea {
width: 100%;
padding: 10px;
outline: none;
resize: none;
border: none;
border-bottom: 1px solid var(--contrast-color);
}
input[type="text"]:focus,
textarea:focus {
border-bottom: 2px solid var(--main-color);
}
textarea::-webkit-scrollbar {
width: 4px;
}
textarea::-webkit-scrollbar-thumb {
background-color: var(--contrast-color);
}
.center {
text-align: center;
width: 602px;
font-size: 20px;
}
input[type="submit"] {
margin-top: 30px;
width: 100%;
max-width: 200px;
background-color: var(--netural-color);
font-size: 17px;
color: var(--contrast-color);
font-weight: 400;
cursor: pointer;
}
I have been trying to make it responsive cause my form doesn't shrink down and there isn't any padding on the left and right when the screen keeps getting
smaller:
#media screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.contact_form input textarea {
width: 70%;
margin-top: 0;
.home-section {
height: 100vh;
}
section {
height: 100%;
width: 100%;
}
}

Based on your code I suspect the .center and it's fixed width is setting the width of your form. Just remove that width or make it responsive.
.center {
text-align: center;
width: 602px;
font-size: 20px;
}
<form>
<div class="center">
<input type="submit" value="Send Message" />
</div>
</form>

Related

Header and footer being pushed left at 375 & 320 mobile view, but fine in all else?

So my footer and header (header is ONLY an image btw) are being pushed left once i go to 375 or 320 mobile view. But on all else it's totally fine, 425px view included. I have tried removing the form margin/padding and fieldset margin/padding, that made no difference. I have tried using background cover/fill for the header image, that did nothing either.
Everything else on the page is right where it should be, only the header and footer are being pushed left at those views.
This is my code
body {
font-family: 'Nunito', sans-serif;
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
* {
box-sizing: border-box;
}
/* Header css */
header {
display: flex;
text-align: center;
}
#header_img {
width: 100%;
max-height: 150px;
}
/* Form css */
form {
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
padding: 0;
}
/* Fieldset and Legend*/
fieldset {
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
padding: 1em;
margin: 1em 0;
border: solid 1px #ccc;
border-radius: 6px;
min-width: 200px;
}
legend {
padding: 0 .25em;
font-size: 1.25em;
color: rgb(34, 34, 34);
}
/* Labels */
label {
display: block;
margin-top: .5em;
}
label:first-of-type {
margin-top: 0;
}
/* Inputs and textarea */
input {
width: 15em;
padding: .5em;
border: solid 1px #999;
font-size: 12px;
}
#first_name, #last_name {
font-weight: bold;
font-size: 14px;
}
#email {
font-style: italic;
}
textarea {
min-height: 8em;
min-width: 100%;
padding: .5em;
border: solid 1px #999;
}
input[type="checkbox"] {
width: 1em;
}
input[type="submit"] {
padding: .5em 1em;
margin-top: 1em;
border-radius: 6px;
background-color: #333;
color: #fff;
font-size: .8em;
width: 7em;
}
input, textarea {
border-radius: 2px;
}
#terms_and_conditions_div {
display: flex;
flex-direction: row;
align-items: baseline;
}
/* Footer css*/
footer {
display: flex;
justify-content: center;
position: absolute;
width: 100%;
text-align: center;
font: 18px bold;
}
/* Large screen rules */
#media screen and (min-width: 430px) {
legend {
font-size: 1.75em;
}
fieldset {
padding: 1em 2em;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght#400&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./main.css">
<title>Event</title>
</head>
<body>
<header>
<img id="header_img" src="./Code_challenge_img.png" alt="Event location image">
</header>
<form id="contact_form" name="contact_form" method="POST">
<fieldset>
<legend>Contact Details</legend>
<label for="first_name">First name:</label>
<input type="text" id="first_name" name="first_name" placeholder="First name" maxlength="30">
<label for="last_name">Last name:</label>
<input type="text" id="last_name" name="last_name" placeholder="Last name" maxlength="30">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" placeholder="Phone number" maxlength="30">
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="Email" maxlength="50">
<label for="promo_code">Promo Code:</label>
<input type="text" name="promo_code" id="promo_code" placeholder="Promo code" maxlength="7">
<label for="how_did_you_hear_menu">How did you hear:</label>
<select name="how_did_you_hear_menu" id="how_did_you_hear_menu">
<option value="Social Media">Social Media</option>
<option value="From a friend">From a friend</option>
<option value="Email">Email</option>
<option value="Other">Other</option>
</select>
<label for="how_did_you_hear_other">Please specify:</label>
<textarea name="how_did_you_hear_other" id="how_did_you_hear_other" rows="4" cols="50" placeholder="Please specify" maxlength="255"></textarea>
<div id="terms_and_conditons_div">
<input type="checkbox" name="terms_and_conditions" id="terms_and_conditions">
I agree to the terms and conditions of this event.
</div>
<input type="submit" id="form_submit_btn" value="Submit">
</fieldset>
</form>
<footer>
<p id="footer_text">For assistance please call 555-5555 or email test#test.com.</p>
</footer>
</body>
</html>
Thanks for any help everyone!
It is not the header or footer. The problem here is the textarea, it is more then 100% width. Change in the html and css the textarea code as shown below to have a correct header/form/footer.
body {
font-family: 'Nunito', sans-serif;
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
* {
box-sizing: border-box;
}
/* Header css */
header {
display: flex;
text-align: center;
}
#header_img {
width: 100%;
max-height: 150px;
}
/* Form css */
form {
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
padding: 0;
}
/* Fieldset and Legend*/
fieldset {
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: center;
padding: 1em;
margin: 1em 0;
border: solid 1px #ccc;
border-radius: 6px;
min-width: 200px;
}
legend {
padding: 0 .25em;
font-size: 1.25em;
color: rgb(34, 34, 34);
}
/* Labels */
label {
display: block;
margin-top: .5em;
}
label:first-of-type {
margin-top: 0;
}
/* Inputs and textarea */
input {
width: 15em;
padding: .5em;
border: solid 1px #999;
font-size: 12px;
}
#first_name, #last_name {
font-weight: bold;
font-size: 14px;
}
#email {
font-style: italic;
}
textarea {
min-height: 8em;
width: 100%;
padding: .5em;
border: solid 1px #999;
}
input[type="checkbox"] {
width: 1em;
}
input[type="submit"] {
padding: .5em 1em;
margin-top: 1em;
border-radius: 6px;
background-color: #333;
color: #fff;
font-size: .8em;
width: 7em;
}
input, textarea {
border-radius: 2px;
}
#terms_and_conditions_div {
display: flex;
flex-direction: row;
align-items: baseline;
}
/* Footer css*/
footer {
display: flex;
justify-content: center;
position: absolute;
width: 100%;
text-align: center;
font: 18px bold;
}
/* Large screen rules */
#media screen and (min-width: 430px) {
legend {
font-size: 1.75em;
}
fieldset {
padding: 1em 2em;
}
}
<header>
<img id="header_img" src="https://placeimg.com/1000/150/animals" alt="Event location image">
</header>
<form id="contact_form" name="contact_form" method="POST">
<fieldset>
<legend>Contact Details</legend>
<label for="first_name">First name:</label>
<input type="text" id="first_name" name="first_name" placeholder="First name" maxlength="30">
<label for="last_name">Last name:</label>
<input type="text" id="last_name" name="last_name" placeholder="Last name" maxlength="30">
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" placeholder="Phone number" maxlength="30">
<label for="email">Email:</label>
<input type="email" name="email" id="email" placeholder="Email" maxlength="50">
<label for="promo_code">Promo Code:</label>
<input type="text" name="promo_code" id="promo_code" placeholder="Promo code" maxlength="7">
<label for="how_did_you_hear_menu">How did you hear:</label>
<select name="how_did_you_hear_menu" id="how_did_you_hear_menu">
<option value="Social Media">Social Media</option>
<option value="From a friend">From a friend</option>
<option value="Email">Email</option>
<option value="Other">Other</option>
</select>
<label for="how_did_you_hear_other">Please specify:</label>
<textarea name="how_did_you_hear_other" id="how_did_you_hear_other" rows="4" placeholder="Please specify" maxlength="255"></textarea>
<div id="terms_and_conditons_div">
<input type="checkbox" name="terms_and_conditions" id="terms_and_conditions">
I agree to the terms and conditions of this event.
</div>
<input type="submit" id="form_submit_btn" value="Submit">
</fieldset>
</form>
<footer>
<p id="footer_text">For assistance please call 555-5555 or email test#test.com.</p>
</footer>
Just wrap the elements you want do be in the center in a <div>, and style them to be position: relative; left: 50%;, so this will allow them to be 50% which is in the center, depending on the device.
EDIT: I have done some research and 50% positioning does not center the element, instead use position: relative; left: 50%; just like last, but them use margin-left: -30%;. And this will definetely center the element.

A form and a coloured grid inline with each other

I have a contact form that has a width of 45% of the parent div. Instead of white space next to it, I'd like to add a coloured div (a square grid) and add some relevant info within said coloured div. However, with my current code, I'm, unable to get the form and div inline.
I've read some SO posts this one, but they are unable to assist (maybe it's the way I have my current CSS code)
#contact {
width: 90%;
height: 700px;
margin-left: 5%;
background-color: #fff;
border-radius: 10px;
color: #000 !important;
margin: 0 auto;
clear: none;
}
#contact #header {
padding: 10px 0px;
width: 100%;
font-size: 36px;
float: left;
}
#contact-text {
font-size: 16px;
width: 45%;
}
textarea, input, #contact-text {
font-family: Quicksand;
font-size: 16px;
}
label {
display: block;
padding: 1rem 0 .5rem;
text-transform: uppercase;
font-size: 22px;
}
input, textarea {
display: block;
width: 45%;
border: 1px solid black;
padding: .5rem;
}
textarea {
height: auto;
resize: none;
}
button {
font-family: Quicksand;
font-size: 18px;
border: 1px solid black;
padding:.5rem;
width: auto;
text-transform: uppercase;
}
button:hover {
cursor: pointer;
}
#contact #grid {
height: 100%
width: 50%;
background-color: #bbc6cb;
float: right;
overflow: hidden;
display: inline;
}
<div id = "contact">
<div id = "header">
<h3>Contact.</h3>
</div>
<div id = "contact-text">
<p>Please fill out the quick form below and we will get in touch as soon as we can</p>
</div>
<form action="/" id="contact-form" method="post" role="form">
<div class = "label">
<label for="name" class="formText">Name:</label>
</div>
<input id="name" name="name" type="text" placeholder="Your name" required="required">
<div class = "label">
<label for="email" class="formText">Email:</label>
</div>
<input id="email" name="email" type="text" placeholder="Your email" required="required">
<div class = "label">
<label for="message" class="formText">Message:</label>
</div>
<textarea id="message" name="message" placeholder="Enter your message here" rows="10" required="required"></textarea>
<div>
<button type="submit">Send</button>
</div>
</form>
<div id = "grid">
</div>
</div>
Use this below code:
#contact {
height: 700px;
background-color: #fff;
border-radius: 10px;
color: #000 !important;
margin: 0 auto;
clear: none;
max-width: 1140px;
}
.left-gird, .right-grid {
width: 49%;
float: left;
}
.left-gird {
margin-right: 1%;
}
.right-gird {
margin-left: 1%;
}
.color-box {
height: 400px;
background-color: gray;
}
#contact #header {
padding: 10px 0px;
width: 100%;
font-size: 36px;
float: left;
}
#contact-text {
font-size: 16px;
width: 45%;
}
textarea, input, #contact-text {
font-family: Quicksand;
font-size: 16px;
}
label {
display: block;
padding: 1rem 0 .5rem;
text-transform: uppercase;
font-size: 22px;
}
input, textarea {
display: block;
width: 100%;
border: 1px solid black;
padding: .5rem;
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
textarea {
height: auto;
resize: none;
}
button {
font-family: Quicksand;
font-size: 18px;
border: 1px solid black;
padding:.5rem;
width: auto;
text-transform: uppercase;
}
button:hover {
cursor: pointer;
}
#contact #grid {
height: 100%;
width: 50%;
background-color: #bbc6cb;
float: right;
overflow: hidden;
display: inline;
}
h3 {
margin-top: 0;
}
<div id = "contact">
<div class="left-gird">
<div id = "header">
<h3>Contact.</h3>
</div>
<div id = "contact-text">
<p>Please fill out the quick form below and we will get in touch as soon as we can</p>
</div>
<form action="/" id="contact-form" method="post" role="form">
<div class = "label">
<label for="name" class="formText">Name:</label>
</div>
<input id="name" name="name" type="text" placeholder="Your name" required="required">
<div class = "label">
<label for="email" class="formText">Email:</label>
</div>
<input id="email" name="email" type="text" placeholder="Your email" required="required">
<div class = "label">
<label for="message" class="formText">Message:</label>
</div>
<textarea id="message" name="message" placeholder="Enter your message here" rows="10" required="required"></textarea>
<div>
<button type="submit">Send</button>
</div>
</form>
</div>
<div class="right-grid">
<div class="color-box"> color box here</div>
</div>
</div>
Use float:left for form and next div for inline
#contact {
width: 90%;
height: 700px;
margin-left: 5%;
background-color: #fff;
border-radius: 10px;
color: #000 !important;
margin: 0 auto;
clear: none;
}
#contact #header {
padding: 10px 0px;
width: 100%;
font-size: 36px;
float: left;
}
#contact-text {
font-size: 16px;
width: 45%;
}
textarea, input, #contact-text {
font-family: Quicksand;
font-size: 16px;
}
label {
display: block;
padding: 1rem 0 .5rem;
text-transform: uppercase;
font-size: 22px;
}
input, textarea {
display: block;
width: 90%;
border: 1px solid black;
padding: .5rem;
}
textarea {
height: auto;
resize: none;
}
button {
font-family: Quicksand;
font-size: 18px;
border: 1px solid black;
padding:.5rem;
width: auto;
text-transform: uppercase;
}
button:hover {
cursor: pointer;
}
form{
float:left;
width:50%;
}
#contact #grid {
height: 100%;
width: 50%;
background-color: #bbc6cb;
float: right;
overflow: hidden;
float:left;
}
<div id = "contact">
<div id = "header">
<h3>Contact.</h3>
</div>
<div id = "contact-text">
<p>Please fill out the quick form below and we will get in touch as soon as we can</p>
</div>
<form action="/" id="contact-form" method="post" role="form">
<div class = "label">
<label for="name" class="formText">Name:</label>
</div>
<input id="name" name="name" type="text" placeholder="Your name" required="required">
<div class = "label">
<label for="email" class="formText">Email:</label>
</div>
<input id="email" name="email" type="text" placeholder="Your email" required="required">
<div class = "label">
<label for="message" class="formText">Message:</label>
</div>
<textarea id="message" name="message" placeholder="Enter your message here" rows="10" required="required"></textarea>
<div>
<button type="submit">Send</button>
</div>
</form>
<div id = "grid">
</div>
</div>

CSS - Styling a form

I'm styling a form for a site and I need it to look like this -
My coded version, so far, looks like this -
The name & email sections for some reason won't size properly and there seems to be padding or margin properties somewhere which I can't seem to override. Here's my code as it stands -
form {
height: 200px;
width: 400px;
margin-right: 50px;
}
.name {
float: left;
}
input[type=text],
input[type=email] {
background: #F0F0F0;
font-size: 10px;
width: 100%;
height: 20px;
}
input[type=subject] {
background: #F0F0F0;
font-size: 10px;
width: 100%;
height: 20px;
}
textarea {
resize: vertical;
font-size: 10px;
width: 100%;
background: #F0F0F0;
height: 100px;
}
input[type=submit] {
background: #00bfff;
border: none;
color: #ffffff;
cursor: pointer;
font-size: 10px;
font-weight: 700;
width: 100%;
}
<div class="six columns">
<form>
<fieldset>
<div class="name">
<input type="text" required placeholder="NAME">
</div>
<div class="name">
<input type="email" required placeholder="EMAIL">
</div>
<div>
<input type="subject" placeholder="SUBJECT">
</div>
<div>
<textarea placeholder="MESSAGE..."></textarea>
</div>
</fieldset>
<input type="submit" value="SUBMIT">
</form>
</div>
UPDATE - Latest version.
I made a bunch of tweaks and kind of last track as I went, so I hope you're able to read through this and figure it out. If not, please feel free to ask questions!
form {
height: 200px;
width: 400px;
margin-right: 50px;
}
fieldset {
border: none;
padding: 0;
margin: 0;
display: flex;
}
div.row {
display: flex;
width: 100%;
}
div.row input {
margin-left: 5px;
}
div.row input:first-child {
margin-left: 0;
}
input[type=text],
input[type=email] {
background: #E8E8E8;
font-size: 10px;
width: 100%;
box-sizing: border-box;
border: 0;
padding: 0;
margin-bottom: 5px;
padding: 6px 12px;
}
textarea {
resize: none;
font-size: 10px;
background: #E8E8E8;
width: 100%;
box-sizing: border-box;
border: 0;
padding: 6px 12px;
margin-bottom: 5px;
}
input[type=submit] {
background: #1ba4dd;
border: none;
color: #ffffff;
cursor: pointer;
font-size: 10px;
font-weight: 700;
width: 100%;
padding: 8px 0;
}
input[type=submit]:hover {
background: #00bfff;
}
<div class="six columns">
<form>
<fieldset>
<div class="row">
<input name="name" type="text" required placeholder="NAME">
<input name="email" type="email" required placeholder="EMAIL">
</div>
<input name="subject" type="text" placeholder="SUBJECT">
<textarea rows="8" placeholder="MESSAGE..."></textarea>
</fieldset>
<input type="submit" value="SUBMIT">
</form>
</div>

Margin of Paragraph Tag goes outside of Div

Extra margin from a paragraph tag is forcing a button downwards. I am trying to understand why.
Here's one answer I tried looking to find an answer from : is it a bug? margins of P element go outside the containig div, however the answer quotes "collapsing margins" but I don't understand why that would be a correct answer, as margins don't seem to be collapsing in this case but expanding.
I understand the problem can be fixed by giving the paragraph tag a margin of 0, but I want to know why the margin is bleeding, and (if is due to margin collapse), a more verbose explanation from the other answer..
.body {
height: 100%;
}
.error {
color: red;
}
#chatbox {
width: 500px;
height: 500px;
background-color: #93ff95;
border: 1px solid black;
}
#loginContainer {
text-align: right;
height: 50px;
line-height: 50px;
}
#loginContainer input {
height: 25px;
font-size: 16px;
}
input#login {
text-transform: uppercase;
background: none;
color: blue;
border: none;
}
#loginForm {
margin: auto;
display: block;
}
#messagesArea {
height: 350px;
background-color: white;
padding: 5px;
}
#messageBox {
height: 100px;
padding: 1px 1px;
}
#messageForm {
display: none;
}
#messageBoxBlocked {
width: 100%;
height: 100%;
border: none;
border-radius: 5px;
padding: 0;
margin: none;
}
<div id="chatbox">
<div id="loginContainer">
<form id='loginForm'>
<span class="error">Invalid Username</span>
<input type="text" name="username" placeholder="Enter a username"/>
<input id="login" type="submit" name="login" value="Login"/>
</form>
</div>
<div id="messagesArea">
<p>Admin: Hey Everyone!</p>
</div>
<div id="messageBox">
<button id="messageBoxBlocked">Log in to enter chat</button>
<form id="messageForm">
<textarea name="messageBox" placeholder="Enter a message"></textarea>
<input type="submit" name="Send"/>
</form>
</div>
</div>
There isn't a problem with the margin of the p-tag.
Your #messagesArea height is too high. You can fix it by decreasing it to height: 338px; as shown in the example below:
.body {
height: 100%;
}
.error {
color: red;
}
#chatbox {
width: 500px;
height: 500px;
background-color: #93ff95;
border: 1px solid black;
}
#loginContainer {
text-align: right;
height: 50px;
line-height: 50px;
}
#loginContainer input {
height: 25px;
font-size: 16px;
}
input#login {
text-transform: uppercase;
background: none;
color: blue;
border: none;
}
#loginForm {
margin: auto;
display: block;
}
#messagesArea {
height: 338px;
background-color: white;
padding: 5px;
}
#messageBox {
height: 100px;
padding: 1px 1px;
}
#messageForm {
display: none;
}
#messageBoxBlocked {
width: 100%;
height: 100%;
border: none;
border-radius: 5px;
padding: 0;
margin: none;
}
<div id="chatbox">
<div id="loginContainer">
<form id='loginForm'>
<span class="error">Invalid Username</span>
<input type="text" name="username" placeholder="Enter a username"/>
<input id="login" type="submit" name="login" value="Login"/>
</form>
</div>
<div id="messagesArea">
<p>Admin: Hey Everyone!</p>
</div>
<div id="messageBox">
<button id="messageBoxBlocked">Log in to enter chat</button>
<form id="messageForm">
<textarea name="messageBox" placeholder="Enter a message"></textarea>
<input type="submit" name="Send"/>
</form>
</div>
</div>

HTML Elements are same height yet one is visually bigger that the other

The "login the enter chat" button is supposed to fit inside the messageBox div, but is (visually) way bigger than messageBox. I even made padding and margin 0 but it did not change anything.
What is the culprit here (besides myself)?
#chatbox {
width: 500px;
height: 500px;
background-color: lime;
border: 1px solid black;
}
#loginContainer {
text-align: right;
height: 50px;
line-height: 50px;
}
#loginContainer input {
height: 25px;
font-size: 16px;
}
input#login {
text-transform: uppercase;
background: none;
color: blue;
border: none;
}
#loginForm {
margin: auto;
display: block;
}
#messagesArea {
height: 350px;
background-color: white;
padding: 5px;
}
#messageBox {
height: 100px;
padding: 1px 1px;
}
#messageForm {
display: none;
}
#messageBoxBlocked {
width: 100%;
height: 100%;
border: none;
border-radius: 5px;
padding: 0;
margin: 0;
}
<h1>Chat with Customer Service</h1>
<div id="chatbox">
<div id="loginContainer">
<form id='loginForm'>
<input type="text" name="username" placeholder="Enter a username"/>
<input id="login" type="submit" name="login" value="Login"/>
</form>
</div>
<div id="messagesArea">
<p>Admin: Hey Everyone!</p>
</div>
<div id="messageBox">
<button id="messageBoxBlocked">Log in to enter chat</button>
<form id="messageForm">
<textarea name="messageBox" placeholder="Enter a message"></textarea>
<input type="submit" name="Send"/>
</form>
</div>
</div>
The p element inside your #messagesArea has a margin values.
The #messagesArea has padding.
Remove these two and you are done :)
#messagesArea {
padding: 0;
}
#messagesArea p {
margin: 0;
}
Here is a working example:
#chatbox {
width: 500px;
height: 500px;
background-color: lime;
border: 1px solid black;
}
#loginContainer {
text-align: right;
height: 50px;
line-height: 50px;
}
#loginContainer input {
height: 25px;
font-size: 16px;
}
input#login {
text-transform: uppercase;
background: none;
color: blue;
border: none;
}
#loginForm {
margin: auto;
display: block;
}
#messagesArea {
height: 350px;
background-color: white;
padding: 0;
}
#messagesArea p {
margin: 0;
}
#messageBox {
height: 100px;
padding: 1px 1px;
}
#messageForm {
display: none;
}
#messageBoxBlocked {
width: 100%;
height: 100%;
border: none;
border-radius: 5px;
padding: 0;
margin: 0;
}
<h1>Chat with Customer Service</h1>
<div id="chatbox">
<div id="loginContainer">
<form id='loginForm'>
<input type="text" name="username" placeholder="Enter a username"/>
<input id="login" type="submit" name="login" value="Login"/>
</form>
</div>
<div id="messagesArea">
<p>Admin: Hey Everyone!</p>
</div>
<div id="messageBox">
<button id="messageBoxBlocked">Log in to enter chat</button>
<form id="messageForm">
<textarea name="messageBox" placeholder="Enter a message"></textarea>
<input type="submit" name="Send"/>
</form>
</div>
</div>
Note - if you do need these margin/padding values - make sure you set the container (#chatbox) with the correct height value. In your case - it should be 512px - it will include the padding of the #messageArea and the border of the #messageBox).