How to match HTML input and select styles with CSS - html

I'm trying to match the styles of both HTML <input> and the <select> tags with all fonts and size in their borders but I can't seem to find a solution for this. I have tried using the same code I used for <input>, have a bigger width for the <select> tag, or even use a bigger padding for the element but I can't seem to make it work. What I have is this:
#import url('https://fonts.googleapis.com/css?family=Sulphur+Point&display=swap');
body {
background-image: url(http://wallpapercave.com/wp/c2apnKi.jpg);
font-family: 'Sulphur Point', sans-serif;
}
#main {}
#title {
color: #FFF;
text-align: center;
}
#description {
color: #FFF;
text-align: center;
}
#survey-form {
padding: 15px;
background-color: lightblue;
width: 700px;
display: block;
margin-left: auto;
margin-right: auto;
}
label {
display: block;
margin-left: 5.8em;
margin-top: 1em;
}
#name {
width: 70%;
padding: 10px;
display: block;
margin-left: auto;
margin-right: auto;
}
#email {
display: block;
width: 70%;
padding: 10px;
margin-left: auto;
margin-right: auto;
}
#number {
display: block;
width: 70%;
padding: 10px;
margin-left: auto;
margin-right: auto;
}
#dropdown {
width: 70%;
padding: 20px;
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
font-family: "Sulphur-Point", sans-serif;
border: none;
}
<main>
<h1 id="title">freeCodeCamp Survey Form</h1>
<p id="description">Thank you for taking the time to help us improve the platform</p>
<div>
<form id="survey-form">
<label for="name">Name</label><br>
<input type="text" id="name" name="fname" placeholder="Enter your name">
<label for="email">Email</label><br>
<input type="email" id="email" name="emailaddress" placeholder="Enter your email" required>
<label for="age">Age (optional)</label><br>
<input type="number" id="number" name="age" placeholder="Age" min="1" max="100">
<label for="role">Which option best describes your current role?</label><br>
<select id="dropdown">
<option value "" disable selected hidden>Select current role</option>
<option value="">Student</option>
<option value="">Full Time Job</option>
</form>
</div>
</main>
Any ideas on how can I fix this?

First ensure that both your <input> and <select> have the same padding (I've set it to 10px in my example), and then simply add the box-sizing: content-box CSS rule. This changes how width is derived, and needs to be applied to #dropdown, though you would benefit from instead adding it to every element on your page with the wildcard selector *:
* {
-ms-box-sizing: content-box;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
}
#import url('https://fonts.googleapis.com/css?family=Sulphur+Point&display=swap');
body {
background-image: url(http://wallpapercave.com/wp/c2apnKi.jpg);
font-family: 'Sulphur Point', sans-serif;
}
#main {}
#title {
color: #FFF;
text-align: center;
}
#description {
color: #FFF;
text-align: center;
}
#survey-form {
padding: 15px;
background-color: lightblue;
width: 700px;
display: block;
margin-left: auto;
margin-right: auto;
}
label {
display: block;
margin-left: 5.8em;
margin-top: 1em;
}
#name {
width: 70%;
padding: 10px;
display: block;
margin-left: auto;
margin-right: auto;
}
#email {
display: block;
width: 70%;
padding: 10px;
margin-left: auto;
margin-right: auto;
}
#number {
display: block;
width: 70%;
padding: 10px;
margin-left: auto;
margin-right: auto;
}
#dropdown {
width: 70%;
padding: 10px;
display: block;
margin-left: auto;
margin-right: auto;
position: relative;
font-family: "Sulphur-Point", sans-serif;
border: none;
}
<main>
<h1 id="title">freeCodeCamp Survey Form</h1>
<p id="description">Thank you for taking the time to help us improve the platform</p>
<div>
<form id="survey-form">
<label for="name">Name</label><br>
<input type="text" id="name" name="fname" placeholder="Enter your name">
<label for="email">Email</label><br>
<input type="email" id="email" name="emailaddress" placeholder="Enter your email" required>
<label for="age">Age (optional)</label><br>
<input type="number" id="number" name="age" placeholder="Age" min="1" max="100">
<label for="role">Which option best describes your current role?</label><br>
<select id="dropdown">
<option value "" disable selected hidden>Select current role</option>
<option value="">Student</option>
<option value="">Full Time Job</option>
</form>
</div>
</main>

Related

I have a body background image <body background="img url here"> and I want to add a grayscale effect to it [duplicate]

This question already has answers here:
How to apply a CSS filter to a background image
(22 answers)
Closed last month.
I have a body background image <body background="img url here"> and I want to add a grayscale effect to it. Tried searching the web but couldn't find a solution. Here is my HTML and CSS
body {
width: 100%;
height: 100%;
text-align: center;
font-family: Helvetica;
color: rgb(255, 255, 255);
font-size: 30px;
}
body {
background-image: url("https://images.pexels.com/photos/1037992/pexels-photo-1037992.jpeg");
filter: grayscale(100%);
background-repeat: no-repeat;
background-size: cover;
}
label[for="email-label"] {
margin-left: 120px;
margin-right: 120px;
}
label[for="name-label"] {
margin-left: 120px;
margin-right: 120px;
}
label[for="age"] {
margin-left: 350px;
margin-right: 350px;
}
label[for="favorite-time"] {
border-top: 6px solid white;
margin-top: 30px;
padding-top: 20px;
}
input[type=radio] {
font-size: 10px;
}
h1 {
margin: 0 auto;
max-width: 1200px;
text-align: center;
border: 30px solid white;
padding: 30px;
border-radius: 25px;
}
p {
margin: 1em auto;
text-align: center;
}
form {
width: 60vw;
max-width: 500px;
min-width: 300px;
margin: 0 auto;
padding-bottom: 2em;
}
fieldset {
border: 9px solid white;
margin-left: -200px;
margin-right: -199px;
padding: 30px;
border-radius: 25px;
margin-top: 50px;
margin-bottom: 110px;
}
label {
display: block;
margin: 0.5rem 0;
}
input,
textarea,
select {
margin: 10px 0 0 0;
width: 100%;
min-height: 2em;
font-size: 25px;
}
select {
margin: 10px 0 0 30;
width: 30%;
min-height: 2em;
font-size: 25px;
}
input,
textarea {
background-color: #3b3b4f;
border: 1px solid #3b3b4f;
color: #ffffff;
}
.inline {
width: unset;
margin: 0 0.5em 0 0;
vertical-align: middle;
}
input[type="submit"] {
width: 60%;
margin: 0 auto;
border: 5px solid white;
font-size: 30px;
background-color: #3b3b4f;
min-width: 300px;
border-radius: 25px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Favorite Media Survey</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body background="https://images.pexels.com/photos/1037992/pexels-photo-1037992.jpeg">
<h1 id="title">Favorite Media Survey</h1>
<p id="description">Thank you for taking the time to share your interests</p>
<form id="survey-form" method="post" action='https://register-demo.freecodecamp.org'>
<fieldset>
<label for="name-label" id="name-label">Name:<input id="name" type="text" name="name-label" placeholder="Bob" required/></label>
<label for="email-label" id="email-label">Email:<input id="email" type="email" name="email-label" placeholder="blank#blank.com" required/></label>
<label for="age" id="number-label">Age:<input id="number" type="number" name="age" min="13" max="120" placeholder="ex.18" required/></label>
</fieldset>
<fieldset>
<label for="tv-movies">Do you like movies or TV shows better?<input type="radio" value="tv-movies" id="tv-movies" name="tv-movies" >Movies</label>
<label for="tv-movies"><input type="radio" value="tv" id="tv-movies" name="tv-movies" >TV</label>
<label for="favorite-media">Do you like books or magazines better?<input type="radio" value="books" id="favorite-media" name="favorite-media">Books</label>
<label for="favorite-media"><input type="radio" value="magazines" id="favorite-media" name="favorite-media">Magazines</label>
<label for="favorite-time">When is your favorite time of the day to interact with media?<input type="checkbox" value="morning" id="Morning" name="Morning">Morning</label>
<input type="checkbox" value="afternoon" id="Afternoon" name="Afternoon">Afternoon</label>
<input type="checkbox" value="night" id="Night" name="Night">Night</label>
</fieldset>
<fieldset>
<label for="genre" id="genre" name="genre">What is your favorite genre?</label>
<select id="dropdown" type="dropdown" name="dropdown">
<option value="0">(select one)</option>
<option value="1">Comedy</option>
<option value="2">Horror</option>
<option value="3">Romance</option>
<option value="4">Fantasy</option>
<option value="5">Sci-Fi</option>
</select>
</fieldset>
<fieldset>
<label for="favorite-element">What is your favorite and why?
<textarea id="favorite-element" name="favorite-element" rows="3" cols="30" placeholder="I really like movies the best because..."></textarea>
</label>
</fieldset>
<input id="submit" type="submit" value="submit">
<hr></hr>
</input>
</form>
</body>
</html>
I tried adding a filter:grayscale(60%) to the body type selector and nothing happened. Also tried wrapping the background in the body element with a <div> and giving that a class and using a class selector to apply a filter which also did not work. I had a working solution before when I added the image to the HTML using img src="" but when I did things that way I couldn't get my image to layer behind my text.
Delete this body background tag and add in css this:
body {
position: relative;
height:400px; // Added only for presentation purpose
}
body::before {
content: "";
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
background-image: url(https://images.pexels.com/photos/1037992/pexels-photo-1037992.jpeg);
filter: grayscale(100%);
background-size: cover; // Added only for presentation purpose
}
<body>
</body>
This is working snippet :)

Why does the background color of the div is not showing when I made the div a responsive square?

I'm trying to make this tribute page and since the box (where the form fields are located) I was making keeps on overlapping the title above, I tried to make the box responsive. However, the background-color disappeared after I've done it, and I don't know how to go from there. This is the HTML code by the way.
<body>
<div id="maintitle-div"><h1 id="maintitle" class="maintitle">atrovska</h1></div>
<div class="box">
<div class="content">
<h1 id="title">💬 Tell us how we're doing! 💬</h1>
<p id="description"> Your feedback matters to us and rest assured we will use this to improve our services even further. </p>
<form id="survey-form">
<label id="name-label">
Name <br> <input type="text" id="name" placeholder="Enter your Name" required> </label><br>
<label id="email-label">
Email <br> <input type="email" id="email" placeholder="Enter your Email" required></label>
<label id="number-label">
<input type="number" id="number" placeholder="Enter your phone number" required max="1" min="5">Number</label>
<p>What services did you avail?</p>
<select name="services" id="dropdown">
<option value="Internet">Internet </option>
<option value="Data">Data</option>
<option value="Post-paid">Post-Paid</option> </select><br>
<p> Please select your service provider.</p>
<input type="radio" name="provider" value="globe">Globe
<input type="radio" name="provider" value="globe">Globe
<input type="radio" name="provider" value="globe">Globe
<p> Please select your service provider.</p>
<input type="checkbox" name="provider" value="globe">Globe
<input type="checkbox" name="provider" value="globe">Globe
<input type="checkbox" name="provider" value="globe">Globe
<textarea></textarea>
<button type="submit" id="submit">Submit</button>
</form>
</div>
</div></body>
And this is the CSS.
#import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght#600&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
:root {
--color-darkBlue: rgb(66, 7, 188);
}
body {
background-image: url(https://i.pinimg.com/originals/6d/25/f2/6d25f2bc9f8c59dc9d5fbab6809126f8.jpg);
background-size: cover;
background-attachment: fixed;
margin: 0;
}
#maintitle {
font-family: 'Press Start 2P', cursive;
color: rgb(255, 201, 14);
margin-top: 5px;
font-size: 48px;
margin: 30px 0 30px auto;
text-align: center;
}
.header {
padding: 0 0.625rem;
margin-bottom: 1.875rem;
}
.box {
border-radius: 15px;
position: relative;
width: 50%;
margin: 0 auto;
background-color: white;
}
.box::after {
content: "";
display: block;
padding-bottom; 100%;
width: 100%;
height: 100%;
background-color: white;
}
.content {
position: absolute;
width: 100%;
height: 100%;
background-color: white;
}
#title {
font-family: 'Fredoka One', cursive;
color: var(--color-darkBlue);
margin-top: 5px;
font-size: 24px;
margin-bottom: 2px;
text-align: center;
}
p {
font-family: 'Open Sans', sans-serif;
color: rgb(66, 7, 188);
font-size: 8px;
}
#description {
font-weight: 900;
font-size: 14px;
margin-top: 10px;
}
#survey-form {
margin: 5px 0 5px auto;
}
input {
margin: 6px 0 5px auto;
}
#survey-form {
font-family: 'Open Sans', sans-serif;
color: black;
font-size: 11px;
}
You have a CSS syntax mistake in your code.
.box::after {
content: "";
display: block;
padding-bottom; 100%;
width: 100%;
height: 100%;
background-color: white;
}
Should be:
.box::after {
content: "";
display: block;
padding-bottom: 100%;
width: 100%;
height: 100%;
background-color: white;
}
End then giving .content class to background-color works:
.content {
position: absolute;
width: 100%;
height: 100%;
background-color: red;
}
Will paint content background to red.

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.

CSS divs not horizontally aligned properly [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 4 years ago.
This is probably a stupid question, but it has been driving me crazy the whole day. I need both divs with the class of contacthor to be aligned on the top, but not forcing them by using margin-top: -x or etc. Here is an image of the issue.
Also, Im new to web design so if I have useless code please explain.
Thanks.
#redcontact {
margin-bottom: 0;
padding-left: 5vh;
font-size: 15px;
line-height: 30px;
background: black;
}
.contacthor {
display: inline-block;
}
form > .contacthor > .input {
color: #C5B358;
font-size: 15px;
background-color: black;
margin-top: 0;
margin-left: 1vh;
margin-bottom: 1vh;
height: 30px;
width: 190px;
display: block;
}
.contacthor > textarea {
color: #C5B358;
font-size: 15px;
font-family: 'Montserrat', sans-serif;
width: 60vh;
height: 25vh;
background: black;
border: 1px;
border-style: solid;
border-radius: 3px;
border-color: grey;
padding-left: 4px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
<div id="redcontact">
<form action="action_page.php">
<div class="contacthor">
<label for="name">Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<p>Mensaje</p>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
I would agree with Chere's answer in that you should be using something like CSS Grid or Flexbox. However, if you want to stay simple for this example, or just want to know why your code isn't working, here is a solution:
#redcontact {
margin-bottom: 0;
padding-left: 5vh;
font-size: 15px;
line-height: 30px;
background: black;
}
.contacthor {
display: inline-block;
}
form>.contacthor>.input {
color: #C5B358;
font-size: 15px;
background-color: black;
margin-top: 0;
margin-left: 1vh;
margin-bottom: 1vh;
height: 30px;
width: 190px;
display: block;
}
.contacthor>textarea {
color: #C5B358;
font-size: 15px;
font-family: 'Montserrat', sans-serif;
width: 60vh;
height: 25vh;
background: black;
border: 1px;
border-style: solid;
border-radius: 3px;
border-color: grey;
padding-left: 4px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
.contacthor>p {
margin-bottom: 5px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
.contacthor>input[value=enviar] {
display: block;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
/* ===== Styles to fix example ===== */
label, p {
color: white;
}
/* ===== Styles to answer your question ===== */
.contacthor {
vertical-align: top;
}
<div id="redcontact">
<form action="action_page.php">
<div class="contacthor">
<label for="name">Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<p>Mensaje</p>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
The main thing to take away from this is the addition of vertical-align: top. Here is a similar question and here is the documentation for the vertical-align property.
Note: I think there may have been some CSS missing, so the snippet looks a bit odd and I had to make a couple of unrelated changes.
Why is there a . before the input?
Also, I highly recommend not using vh or pixels. You should go with em. Without doing everything, you should probably try to do something like that, with flexbox.
#redcontact {
width: 100%;
height: 100%;
font-size: 15px;
line-height: 1.5;
background-color: #000;
color: #fff;
}
form {
display: flex;
padding: 2em;
.contacthor {
display: flex;
flex-direction: column;
width: 50%;
padding: 0 2em;
input,
textarea {
color: #C5B358;
background-color: transparent;
margin-left: 1em;
margin-bottom: 1em;
padding: 0.5em 1em;
width: auto;
display:block;
}
input {
border: 0;
}
textarea {
border: 1px solid grey;
border-radius: 3px;
}
}
}
I have made a grid. See if you are looking for somewhat similar thing.
https://codepen.io/kalpeshshende/pen/qJjomO
form{
display:grid;grid-gap:10px;
grid-template-columns:1fr 2fr;
}
.holder{
max-width:600px;
margin:auto;
background:black;
color:#C5B358;padding:10px;
}
.contacthor{
display:grid;grid-gap:10px;
}
textarea{
height:100px;
}
input[type=submit]{
width:120px;
}
p{
padding:0px;
}
input[type=text]{
background:black;
color:;border:none;
}
Markup :
<body>
<div class="holder">
<form action="">
<div class="contacthor">
<label for="name" >Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<label for="Mensaje">Mensaje</label>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
</body>
Try adding vertical-align: top; to contracthor.

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>