Aligning label with input type text - html

Good day all. I am currently doing a form in html and css. I tried researching on the internet but somehow the code there is would either cause my textbox to lose its design and look plain or it would be very ugly.
I am trying to align the textbox with the labels so that it would look neat.
I also want to make the submit and reset button align in the center next to each other.
And the radio buttons to make them in a straight line instead of being seperated on 2 lines.
When I removed the code for the class .firstform select, type, I lose my design properties for the textboxes but the buttons managed to be align.
body {
background: url(ewp.jpg);
background-size: cover;
}
.firstform {
order-radius: 5px;
background: green;
padding: 20px;
width: 550px;
margin: auto;
color: #fff;
font-size: 16px;
font-family: verdana;
margin-top: 100px;
opacity: 0.8;
}
.firstform h1 {
text-align: center;
margin: 0;
padding: 0;
}
.firstform input,
select {
width: 50%;
padding: 12px 20px;
margin-left: 16em;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
background: black;
color: white;
opacity: 0.9;
}
.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 24em;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide browser default radio button */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 15px;
width: 15px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196f3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.container .checkmark:after {
top: 6px;
left: 6px;
width: 4px;
height: 4px;
border-radius: 50%;
background: white;
}
.buttonHolder {
display: block;
margin: 0 auto;
}
.firstform input[type="submit"]:hover {
background: #45a049;
transparent: 0.6s;
}
.firstform input[type="reset"]:hover {
background: #45a059;
transparent: 0.6s;
}
<div class="firstform">
<h1>Student Registration Form</h1>
<form action="Form1.php" method="post">
<p><label>First Name: <input type="text" name ="fname" placeholder="First Name" maxlength="25"></label></p>
<p><label>Last Name: <input type="text" name="lname" placeholder="Last Name" maxlength="25"></label></p>
<p><label>Age: <input type="number" name= "age" min="0" max="150"></label></p>
<p><label> Date of Birth:<input type="date" name="date"></label></p>
<p>Gender:
<label class="container">
<input type="radio" name="gender" value="Male">Male
<span class="checkmark"></span>
</label>
<label class="container">
<input type="radio" name="gender" value="Female">Female
<span class="checkmark"></span>
</label>
</p>
<p> Nationality:
<label>
<select name="nationality">
<option selected>Malaysia</option>
<option>Bangladesh</option>
<option>India</option>
<option>African Nations</option>
<option>South East Asia nations</option>
<option>others</option>
</select>
</label>
</p>
<p><label>Address:<input type="text" name="address" size="30" /></label></p>
<p><label>Postcode: <input type="number" name="postcode" min="0" maxlength="5" oninput="this.value=this.value.slice(0,this.maxLength)"></label></p>
<p><label>State:
<input name="state" list="state">
<datalist id="state">
<option value="Selangor">
<option value="Kuala Lumpur">
<option value="Kelantan">
<option value="Johor">
<option value="Malacca">
<option value="Perak">
<option value="Pahang">
<option value="Negeri Sembilan">
<option value="Sabah">
<option value="Sarawak">
<option value="Perlis">
<option value="Kedah">
<option value="Terengganu">
<option value="Penang">
</datalist>
</label></p>
<p>
<label>Email:
<input type="email" name="email">
</label>
</p>
<p>
<label> Tel:
<input type="tel" name="tel" placeholder="(###) ###-####" oninput="this.value=this.value.slice(0,this.maxLength)" maxlength="10">
</label>
</p>
<div class="buttonHolder">
<input type="submit" name="Insert">
<input type="reset" name="Clear">
</div>
</form>
</div>

Working fiddle: https://jsfiddle.net/jennifergoncalves/nut5mzgj/10/
body {
background: url(ewp.jpg);
background-size: cover;
}
.firstform {
order-radius: 5px;
background: green;
padding: 20px;
width: 550px;
margin: auto;
color: #fff;
font-size: 16px;
font-family: verdana;
margin-top: 100px;
opacity: 0.8;
}
.firstform h1 {
text-align: center;
margin: 0;
padding: 0;
}
.firstform input,
select {
width: 50%;
padding: 12px 20px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
background: black;
color: white;
opacity: 0.9;
/* removed margin-left */
}
.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 24em;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide browser default radio button */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 15px;
width: 15px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.container:hover input~.checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.container input:checked~.checkmark {
background-color: #2196f3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.container input:checked~.checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.container .checkmark:after {
top: 6px;
left: 6px;
width: 4px;
height: 4px;
border-radius: 50%;
background: white;
}
.buttonHolder {
display: block;
margin: 0 auto;
}
.firstform input[type="submit"]:hover {
background: #45a049;
transparent: 0.6s;
}
.firstform input[type="reset"]:hover {
background: #45a059;
transparent: 0.6s;
}
label > span, p > span {
width: 50%;
display: inline-block;
}
<div class="firstform">
<h1>Student Registration Form</h1>
<form action="Form1.php" method="post">
<p><label><span>First Name: </span><input type="text" name ="fname" placeholder="First Name" maxlength="25"></label></p>
<p><label><span>Last Name: </span><input type="text" name="lname" placeholder="Last Name" maxlength="25"></label></p>
<p><label><span>Age: </span><input type="number" name= "age" min="0" max="150"></label></p>
<p><label><span>Date of Birth:</span><input type="date" name="date"></label></p>
<p><span>Gender:</span>
<label class="container">
<input type="radio" name="gender" value="Male">Male
<span class="checkmark"></span>
</label>
<label class="container">
<input type="radio" name="gender" value="Female">Female
<span class="checkmark"></span>
</label>
</p>
<p><label><span>Nationality:</span><select name="nationality">
<option selected>Malaysia</option>
<option>Bangladesh</option>
<option>India</option>
<option>African Nations</option>
<option>South East Asia nations</option>
<option>others</option>
</select>
</label>
</p>
<p><label><span>Address:</span><input type="text" name="address" size="30" /></label></p>
<p><label><span>Postcode: </span><input type="number" name="postcode" min="0" maxlength="5" oninput="this.value=this.value.slice(0,this.maxLength)"></label></p>
<p><label><span>State:</span><input name="state" list="state">
<datalist id="state">
<option value="Selangor">
<option value="Kuala Lumpur">
<option value="Kelantan">
<option value="Johor">
<option value="Malacca">
<option value="Perak">
<option value="Pahang">
<option value="Negeri Sembilan">
<option value="Sabah">
<option value="Sarawak">
<option value="Perlis">
<option value="Kedah">
<option value="Terengganu">
<option value="Penang">
</datalist>
</label></p>
<p>
<label><span>Email:</span><input type="email" name="email">
</label>
</p>
<p>
<label><span>Tel:</span><input type="tel" name="tel" placeholder="(###) ###-####" oninput="this.value=this.value.slice(0,this.maxLength)" maxlength="10">
</label>
</p>
<div class="buttonHolder">
<input type="submit" name="Insert"><input type="reset" name="Clear">
</div>
</form>
</div>
The issues were that you had a margin to the left of the inputs. This was preventing the elements from being inline because it added to the horizontal space needed.
Secondly, your inputs are inside your labels. This is fine practice since you can avoid using for attributes for accessibility. However, you can't target just the label, so I surrounded the actual label text with a span. Now you can just target the actual label text. Setting this to 50% and having the inputs at 50% with display:inline-block on both will solve this issue.

I suggest looking into flexbox for these kind of issues. It gives you the ability to be completely flexible about how you align your elements. Here you can find a good explanation:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

3 issues here, to fix the problem
You have enclosed the <input> inside the <label>. Move it out, close the </label> and then start the <input>
remove the margin-left of the input
give display: inline-block; width: 50%; to the label
So your code looks like this now:
jsfiddle: https://jsfiddle.net/vg3ts1m0/3/
jsfiddle (full screen): https://jsfiddle.net/vg3ts1m0/3/show
I have edited first few items in it. It will give you an idea on how to proceed.
I hope it helps.

I am trying to align the textbox with the labels so that it would look neat.
// Layout will resolve 90% of vertical alignment issues.
// To unify form controls (ex. `<input>`, `<select>`, etc) apply the following
input, select, label {display: inline-block; font: inherit}
I also want to make the submit and reset button align in the center next to each other.
/*
Wrap the buttons in a block element (ex. `<fieldset>`, `<div>`, etc)
and center the block
*/
fieldset {width: fit-content; margin: 0 auto}
<fieldset><input type='reset'><input type='submit'></fieldset>
And the radio buttons to make them in a straight line instead of being seperated on 2 lines.
/*
Dimensions should be adjusted as a square (ex. width:4vw; height:4vh;)
The following styles align everything vertically. Keep the height and
line-height the same.
*/
[type=radio] {height: 5vh; line-height: 5vh; vertical-align: middle}
Intrinsic lengths (vw and vh) are used to make the whole form so that it's responsive (see demo in full page mode.
Demo
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
font: 700 5vh/1.1 Verdana;
}
body {
overflow-x: hidden;
overflow-y: scroll;
}
form {
width: 100%;
height: 100%;
padding: 0;
margin: 0 auto;
}
fieldset {
padding: 5px;
margin: 1vh auto;
border-radius: 6px;
}
.set1>legend {
margin-bottom: -7px
}
legend {
margin-top: 10px;
}
legend+hr {
width: 30vw;
}
[type=radio] {
width: 4vw;
height: 4vh;
}
input,
select,
label {
display: inline-block;
font: inherit;
margin: 2vh 0 0 0;
height: 6vh;
line-height: 6vh;
vertical-align: middle;
padding: 1px 2px;
border-radius: 4px;
}
#first,
#last {
width: 77vw;
}
#dob {
width: 33vw
}
.set2 label {
min-width: 9vw;
}
.set3 label {
min-width: 10vw;
}
#male {
margin-left: 3vw;
}
label[for=nationality] {
width: 19vw
}
#nationality {
height: 8vh;
line-height 8vh;
}
#address {
width: 71vw;
}
#state {
width: 25vw;
}
#email {
width: 75vw;
}
[type=number],
[type=tel],
[type=date] {
font-family: Consolas;
font-size: 6vh
}
[type='reset'],
[type='submit'] {
width: 15vw;
height: 8vh;
cursor: pointer;
}
[type=submit] {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
margin: 0 0 0 -3px;
padding: 0 0 2px 0;
}
[type=reset] {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
margin: 0 0 0 -3px;
padding: 0 0 2px 0;
}
.set4 {
padding: 4px;
width: fit-content;
margin: 0px auto;
}
hr {
margin-top: 8px;
}
<form id='main'>
<fieldset name='set1' class='set1 set'>
<legend>Student Registration</legend>
<hr>
<fieldset name='set2' class='set2 set'>
<legend>Personal Information</legend>
<label for='first'>First: </label>
<input id='first' name='first' type='text'><br>
<label for='last'>Last: </label>
<input id='last' name='last' type='text'><br>
<label for='dob'>DOB: </label>
<input id='dob' name='dob' type='date'>
<input id='male' name='gender' type='radio' value='male'><label for='male'> Male </label>
<input id='female' name='gender' type='radio' value='female'><label for='female'> Female</label> <br>
<label for='nationality'>Nationality: </label>
<select id='nationality' name='nationality'>
<option value=''>---------------------------</option>
<optgroup label='North America'>
<option value='US'>American</option>
<option value='CA'>Canadian</option>
<option value='MX'>Mexican</option>
</optgroup>
<optgroup label='South America'>
<option value='BR'>Brazilian</option>
<option value='CR'>Costa Rican</option>
<option value='PR'>Peruvian</option>
</optgroup>
<optgroup label='Asia'>
<option value='CN'>Chinese</option>
<option value='JP'>Japanese</option>
<option value='IN'>Indian</option>
</optgroup>
<optgroup label='Europe'>
<option value='GB'>British</option>
<option value='DE'>German</option>
<option value='FI'>Finnish</option>
</optgroup>
<optgroup label='Africa'>
<option value='NG'>Nigerian</option>
<option value='EG'>Egyptian</option>
<option value='ML'>Malian</option>
</optgroup>
<option value='AU'>Australian</option>
</select>
</fieldset>
<hr>
<fieldset name='set3' class='set3 set'>
<legend>Contact Information</legend>
<label for='address'>Address: </label>
<input id='address' name='address' type='text'><br>
<label for='state'>State: </label>
<input id='state' name='state' list='states'>
<datalist id="states">
<option value="California">
<option value="Oregon">
<option value="Washington">
<option value="Nevada">
<option value="Arizona">
</datalist>
<label for='zipcode'>Zip Code: </label>
<input id='zipcode' name='zipcode' type='number' min='85000' max='98999'><br>
<label for='email'>Email: </label>
<input id='email' name='email' type='email'><br>
<label for='tel'>Telephone: </label>
<input id='tel' name='tel' type='tel'>
</fieldset>
<fieldset name='set4' class='set4 set'>
<input type='submit'>
<input type='reset'>
</fieldset>
</fieldset>
</form>

Related

Is it possible to add dropdown in html input tag?

I want to create a responsive form in HTML CSS.
Where I want to include the dropdown inside the input tag of HTML
<input type="number" class="form_input" id="pay" placeholder="">
<label for="pay" class="form_label_pay">you pay</label>
I don't recommend trying to create invalid html by adding a dropdown inside an input. I recommend you just create the illusion of this effect using styling.
form {
max-width: 400px;
display: flex;
}
fieldset {
flex: 1;
border: 1px solid #ccc;
border-radius: 10px;
}
legend {
font: 700 12px arial;
color: #888;
}
.combobox {
display: flex;
}
.combobox>div {
flex: 1;
margin-right: 5px;
}
#payment input {
text-align: right;
}
#payment input,
#payment select {
width: 100%;
margin: 0;
padding: 0;
border: none;
font: 18px Arial;
}
/*Hide number arrows*/
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Firefox */
input[type=number] {
-moz-appearance: textfield;
}
<form id="payment">
<fieldset>
<legend>You Pay</legend>
<div>
<input id="pay" type="number" class="form_input" value="0.00" placeholder="0.00 ">
</div>
</fieldset>
<fieldset>
<legend>You Receive</legend>
<div class="combobox">
<div>
<input id="receive" type="number" class="form_input" value="0.00" placeholder="0.00 ">
</div>
<div>
<select name="payment-provider " id="payment-provider " form="payment ">
<option value="BitCoin ">BTC</option>
<option value="Ethereum ">ETH</option>
<option value="Cardano ">ADA</option>
<option value="Tether ">USDT</option>
</select>
</div>
</div>
</fieldset>
</form>

How to match HTML input and select styles with CSS

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>

How to make radio button like on/off switches using css

I have requirement of radio buttons with on/off method i.e when click on one radio button it should on and when click on second button first button should off but below code is not working as per my expectation.
Here is the snippet for that html and css code:
body {
background: #0288D1;
}
.checkboxes-and-radios {
margin: 80px auto 0;
width: 280px;
padding: 30px;
background: #fafafa;
input {
display: none;
}
label {
cursor: pointer;
padding-right: 35px;
position: relative;
display: block;
font-size: 18px;
padding: 15px 0
}
input[type="checkbox"],
input[type="radio"] {
position: absolute;
visibility: hidden !important;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
&:before,
&:after {
content: '';
position: absolute;
top: 50%;
margin-top: -7.5px;
box-sizing: border-box;
}
&:before {
width: 30px;
height: 15px;
right: 0px;
background: #fff;
border: 1px solid #e4e3e1;
border-radius: 15px;
}
&:after {
width: 15px;
height: 15px;
right: 15px;
background: #BDBDBD;
border-radius: 50%;
transition: all 200ms ease-out;
}
}
input[type="checkbox"]:checked+label,
input[type="radio"]:checked+label {
&:after {
right: 0px;
background: #FF9800;
}
}
}
<div class="checkboxes-and-radios">
<h1>Radios:</h1>
<input type="radio" name="radio-cats" id="radio-1" value="1" checked>
<label for="radio-1">Radio Label 1</label>
<input type="radio" name="radio-cats" id="radio-2" value="2">
<label for="radio-2">Radio Label 2</label>
<input type="radio" name="radio-cats" id="radio-3" value="3" checked>
<label for="radio-3">Radio Label 3</label>
<h1>Checkboxes:</h1>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-1" value="1" checked>
<label for="checkbox-1">Checkbox Label 1</label>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-2" value="2">
<label for="checkbox-2">Checkbox Label 2</label>
<input type="checkbox" name="checkbox-cats[]" id="checkbox-3" value="3" checked>
<label for="checkbox-3">Checkbox Label 3</label>
</div>
expected output:
so how to add css that will look like in image shown in top?
Your code works like a charm for me. In your provided fiddle, the SCSS was not compiled to CSS. Here a compiled version. Radio buttons are switching correctly.
Here also a version on CodePen.
Your CSS is not CSS but SCSS, which has to be compiled to CSS.
You have to use a preprocessor to compile scss to css. You should start reading here:
http://sass-lang.com
body {
background: #0288D1;
}
.checkboxes-and-radios {
margin: 80px auto 0;
width: 280px;
padding: 30px;
background: #fafafa;
}
.checkboxes-and-radios input {
display: none;
}
.checkboxes-and-radios label {
cursor: pointer;
padding-right: 35px;
position: relative;
display: block;
font-size: 18px;
padding: 15px 0;
}
.checkboxes-and-radios input[type="checkbox"],
.checkboxes-and-radios input[type="radio"] {
position: absolute;
visibility: hidden !important;
}
.checkboxes-and-radios input[type="checkbox"]+label:before,
.checkboxes-and-radios input[type="checkbox"]+label:after,
.checkboxes-and-radios input[type="radio"]+label:before,
.checkboxes-and-radios input[type="radio"]+label:after {
content: '';
position: absolute;
top: 50%;
margin-top: -7.5px;
box-sizing: border-box;
}
.checkboxes-and-radios input[type="checkbox"]+label:before,
.checkboxes-and-radios input[type="radio"]+label:before {
width: 30px;
height: 15px;
right: 0px;
background: #fff;
border: 1px solid #e4e3e1;
border-radius: 15px;
}
.checkboxes-and-radios input[type="checkbox"]+label:after,
.checkboxes-and-radios input[type="radio"]+label:after {
width: 15px;
height: 15px;
right: 15px;
background: #BDBDBD;
border-radius: 50%;
transition: all 200ms ease-out;
}
.checkboxes-and-radios input[type="checkbox"]:checked+label:after,
.checkboxes-and-radios input[type="radio"]:checked+label:after {
right: 0px;
background: #FF9800;
}
<div class="checkboxes-and-radios">
<h1>Radios:</h1>
<input type="radio" name="radio-cats" id="radio-1" value="1" checked>
<label for="radio-1">Radio Label 1</label>
<input type="radio" name="radio-cats" id="radio-2" value="2">
<label for="radio-2">Radio Label 2</label>
<input type="radio" name="radio-cats" id="radio-3" value="3" checked>
<label for="radio-3">Radio Label 3</label>
<h1>Checkboxes:</h1>
<input type="checkbox" name="checkbox-cats1" id="checkbox-1" value="1" checked>
<label for="checkbox-1">Checkbox Label 1</label>
<input type="checkbox" name="checkbox-cats2" id="checkbox-2" value="2">
<label for="checkbox-2">Checkbox Label 2</label>
<input type="checkbox" name="checkbox-cats3" id="checkbox-3" value="3" checked>
<label for="checkbox-3">Checkbox Label 3</label>
</div>

How to properly absolute positioning in reactjs

The whole thing is a misunderstanding on my part please ignore!
I have tried to research this problem but the only solution that came up were for react native. My problem basically is that the CSS behaves differently in reactjs environment then in a regular one. Here is what I mean:
class TodoApp extends React.Component {
constructor(props) {
super(props)
this.state = {
items: [
{ text: "Learn JavaScript", done: false },
{ text: "Learn React", done: false },
{ text: "Play around in JSFiddle", done: true },
{ text: "Build something awesome", done: true }
]
}
}
render() {
return (
<form>
<div id="cart">
{/* Cart Header */}
<div id="cart-header">
<div id="edit-icon" className="header-icon">
<p>EDIT</p>
</div>
<div className="header-line"></div>
<div id="payment-icon" className="header-icon">
<p>PAYMENT</p>
</div>
<div className="header-line"></div>
<div id="confirm-icon" className="header-icon">
<p>COMFIRM</p>
</div>
</div>
{/* Cart Body */}
{/* Personal information */}
<div id="cart-body-left" className="cart-body">
<h2>Personal information</h2>
<fieldset id="info-fieldset">
<div id="name" className="input-div-container">
<div id="first-name" className="input-div">
<input type="text" placeholder="First Name"/>
<label className="input-label">First Name</label>
</div>
<div id="last-name" className="input-div">
<input type="text" placeholder="Last Name" />
<label className="input-label">Last Name</label>
</div>
</div>
<div id="email" className="input-div">
<input type="email" placeholder="Email" />
<label className="input-label">Email</label>
</div>
<div id="number" className="input-div">
<input type="text" placeholder="Number" />
<label className="input-label">Number</label>
</div>
<div id="address-apt" className="input-div-container">
<div id="address" className="input-div">
<input type="text" placeholder="Address" />
<label className="input-label">Adress</label>
</div>
<div id="apt" className="input-div">
<input type="text" placeholder="Apt, Unit, etc" />
<label className="input-label">Apt, Unit, etc</label>
</div>
</div>
<div id="zip-city-state" className="input-div-container">
<div id="zip" className="input-div">
<input type="text" placeholder="Zip" />
<label className="input-label">Zip</label>
</div>
<div id="city" className="input-div">
<input type="text" placeholder="City" />
<label className="input-label">City</label>
</div>
<div id="state" className="input-div">
<select id="state-select">
<option value="AL">AL</option>
<option value="AK">AK</option>
<option value="AS">AS</option>
<option value="AZ">AZ</option>
<option value="AR">AR</option>
<option value="CA">CA</option>
<option value="CO">CO</option>
<option value="CT">CT</option>
<option value="DE">DE</option>
<option value="DC">DC</option>
<option value="FM">FM</option>
<option value="FL">FL</option>
<option value="GA">GA</option>
<option value="GU">GU</option>
<option value="HI">HI</option>
<option value="ID">ID</option>
<option value="IL">IL</option>
<option value="IN">IN</option>
<option value="IA">IA</option>
<option value="KS">KS</option>
<option value="KY">KY</option>
<option value="LA">LA</option>
<option value="ME">ME</option>
<option value="MH">MH</option>
<option value="MD">MD</option>
<option value="MA">MA</option>
<option value="MI">MI</option>
<option value="MN">MN</option>
<option value="MS">MS</option>
<option value="MO">MO</option>
<option value="MT">MT</option>
<option value="NE">NE</option>
<option value="NV">NV</option>
<option value="NH">NH</option>
<option value="NJ">NJ</option>
<option value="NM">NM</option>
<option value="NY">NY</option>
<option value="NC">NC</option>
<option value="ND">ND</option>
<option value="MP">MP</option>
<option value="OH">OH</option>
<option value="OK">OK</option>
<option value="OR">OR</option>
<option value="PW">PW</option>
<option value="PA">PA</option>
<option value="PR">PR</option>
<option value="RI">RI</option>
<option value="SC">SC</option>
<option value="SD">SD</option>
<option value="TN">TN</option>
<option value="TX">TX</option>
<option value="UT">UT</option>
<option value="VT">VT</option>
<option value="VI">VI</option>
<option value="VA">VA</option>
<option value="WA">WA</option>
<option value="WV">WV</option>
<option value="WI">WI</option>
<option value="WY">WY</option>
</select>
</div>
</div>
</fieldset>
</div>
{/* Credit Card Information */}
<div id="cart-body-right" className="cart-body">
<h2>Credit Card Information</h2>
<fieldset id="cc-fieldset">
<div id="cc-number" className="input-div">
<input type="number" placeholder="Credit Card Number" />
</div>
<div id="cc-valid" className="input-div-container">
<div id="cc-expiration" className="input-div">
<input type="text" placeholder="MM/YY" />
</div>
<div id="cc-cvv" className="input-div">
<input type="text" placeholder="CVV" />
</div>
<div id="cvv-help" className="input-div">
<img height="18px" width="18px" src="store/img/question-mark.png" />
</div>
</div>
</fieldset>
<div id="cart-stats">
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
<div className="stats">
<span>cart total:</span>
<span>something</span>
</div>
</div>
<div id="terms-conditions">
<div className="checkbox">
<input type="checkbox" id="tc-checkbox" value="0" />
<label htmlFor="tc-checkbox">Bla bla bla </label>
</div>
</div>
</div>
{/* Cart Footer */}
<div className="cart-footer" id="cart-footer-left">
<div id="coupon">
<div id="coupon-input">
<input type="text"/>
</div>
<div id="coupon-button">
<button>hello</button>
</div>
</div>
</div>
<div className="cart-footer" id="cart-footer-right">
</div>
</div>
</form>
)
}
}
ReactDOM.render(<TodoApp />, document.querySelector("#app"))
:root {
--gold: #e5cb51;
--silver: #666666;
--light-silver: #ddd;
}
::placeholder {
color: var(--silver);
}
h2 {
text-align: center;
color: white;
color: var(--light-silver);
font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
}
body {
background-color: black;
}
p {
font-family: Raleway;
}
#cart {
margin: auto;
margin-top: 100px;
width: 800px;
display: grid;
grid-template-areas:
"h h" /* Header */
"bl br" /* Body left right */
"fl fr"; /* Footer left right */
}
#cart-header {
background-color: black;
border: 1.5px solid var(--gold);
border-bottom: 0px;
border-top-left-radius: 1em;
border-top-right-radius: 1em;
grid-area: h;
display: flex;
justify-content: center;
padding: 1em 0;
}
#cart-body-left {
grid-area: bl;
}
#cart-body-right {
grid-area: br;
border-left-width: 0;
}
#cart-footer-left {
grid-area: fl;
border-bottom-left-radius: 1em;
}
#cart-footer-right {
grid-area: fr;
border-bottom-right-radius: 1em;
}
.cart-body {
width: 400px;
height: 400px;
border: 1.5px solid var(--gold);
background-color: black;
}
.cart-footer {
height: 50px;
width: 400px;
background-color: var(--gold);
}
#email {
box-sizing: border-box;
padding-bottom: 1em;
}
#number {
box-sizing: border-box;
}
#state > select{
height: 100%;
border: 1.5px var(--silver) solid;
border-radius: 3px;
}
#cc-paypal-option {
padding-left: 50%;
margin: 1em;
border: 1px solid white;
border-bottom-left-radius: .5em;
border-bottom-right-radius: .5em;
padding-bottom: 1em;
}
#cc-paypal-option > button {
height: 31px;
}
#cart-stats {
margin: 1em;
border: 1.5px var(--gold) solid;
border-radius: .5em;
}
#cart-stats > div:nth-child(2) {
border-top: 1px var(--gold) solid;
border-bottom: 1px var(--gold) solid;
padding: .5em 0;
margin: .5em 0;
}
#coupon {
height: 40px;
width: 300px;
margin: 5px 50px;
background-color: black;
display: flex;
}
#coupon > div {
width: 200px;
position: relative;
}
#coupon-input input {
position: absolute;
height: 100%;
right: 0;
width: 0;
opacity: 1;
transition: all .2s ease-in;
}
#coupon-button button {
height: 100%;
}
#cart-footer-left:hover input[type="text"] {
width: 100px;
opacity: 1;
transition: all .2s ease-out;
}
.header-line {
width: 75px;
height: 0px;
border: 1px solid var(--gold);
margin: auto 0;
background-color: var(--gold);
}
.header-icon {
height: 2em;
width: 120px;
border: 1.5px solid var(--gold);
border-radius: 4px;
margin: .5em 0px;
padding-top: .1em;
}
.active-icon {}
.header-icon:hover {
background-color: var(--gold);
}
.header-icon:hover > p{
color: black;
}
.header-icon > p {
text-align: center;
color: var(--light-silver);
font-weight: bold;
font-family: Montserrat,"Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 1.2em;
letter-spacing: 2px;
line-height: 1.45;
}
.input-label {
visibility: visible;
position: absolute;
display: block;
color: white;
top: 0;
font-size: 1em;
opacity: 1;
transform: translateY(-1.5em);
transition: all 0.2s ease-out;
margin-left: 10px;
display: inline;
}
input:placeholder-shown + label {
opacity: 0;
visibility: hidden;
text-align: center;
transform: translateY(.5em);
}
.input-div-container {
display: flex;
}
.input-div {
position: relative;
padding: 1em;
/* height: 33px; */
}
/* #first-name,
#last-name {
width: 198.5px;
} */
.input-div > input {
width: 100%;
padding: 5px 10px;
border-radius: 3px;
border: 1.5px var(--silver) solid;
display: block;
}
.input-div > input:focus, #state > select:focus {
outline: none;
border: solid var(--gold) 1.5px;
box-shadow: 0 0 5px var(--gold);
}
.stats {
margin: .5em;
display: flex;
justify-content: center;
}
.stats > span {
padding: 0 1em;
color: var(--light-silver);
}
.checkbox {
position: relative;
margin: 1em;
margin-top: 1.3em;
}
.checkbox input[type="checkbox"] {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0;
opacity: 0;
pointer-events: none;
}
.checkbox label::before {
display: block;
position: absolute;
top: 0;
left: 0;
width: 28px;
height: 28px;
background-color: white;
content: '';
}
.checkbox input[type="checkbox"]:checked + label::before {
background-color: var(--gold);
color: white;
}
.checkbox input[type="checkbox"]:checked + label::after {
display: block;
position: absolute;
top: 1px;
left: 8.5px;
width: 10px;
height: 20px;
/* background: black; */
border: solid black;
border-width: 0 3px 3px 0;
transform: rotate(45deg);
content: '';
}
#media screen and (max-width: 900px) {
#cart {
width: 400px;
display: grid;
grid-template-areas:
"h"
"bl"
"fl"
"br"
"fr";
}
#cart-header {
width: 400px;
}
.header-icon {
width: 75px;
}
.header-icon p {
font-size: .7em;
letter-spacing: 2px;
line-height: 2.5;
}
#cart-body-right {
border-left-width: 1.5px;
}
#cart-footer-left {
border-radius: 0px;
}
#cart-footer-right {
border-bottom-left-radius: 1em;
border-bottom-right-radius: 1em;
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="app"></div>
Here is how it looks like when I render it without react
How it looks like after I paste my code into jsx
I hope I have provided enough code and if not I can add on to it
I'm not sure this is a react specific issue. I pasted your code into JSFiddle and did not run into the same issues you are having. Positioned elements will only default to root if there are no other positioned ancestors. Might be worth looking through your HTML to see if there is a positioned parent or ancestor messing with your positioning.

css float select field title on click

I would like to make the select field behave like the other two input fields. After the user fills out the fields, the field title floats on top.
How can I make the select item also behave like the other two input fields? so that by clicking on the field, the placeholder should float to the top.
And the default value shown as the placeholder is Your Letter, which will then move up after selecting a letter or clicking on the field.
body {
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
}
form {
margin: 2em 0;
}
.field {
display: flex;
flex-flow: column-reverse;
margin-bottom: 1em;
}
label, input {
transition: all 0.2s;
touch-action: manipulation;
}
input {
font-size: 1.5em;
border: 0;
border-bottom: 1px solid #ccc;
font-family: inherit;
-webkit-appearance: none;
border-radius: 0;
padding: 0;
cursor: text;
}
input:focus {
outline: 0;
border-bottom: 1px solid #666;
}
label {
text-transform: uppercase;
letter-spacing: 0.05em;
}
input:placeholder-shown + label {
cursor: text;
max-width: 66.66%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transform-origin: left bottom;
transform: translate(0, 2.125rem) scale(1.5);
}
::-webkit-input-placeholder {
opacity: 0;
transition: inherit;
}
input:focus::-webkit-input-placeholder {
opacity: 1;
}
input:not(:placeholder-shown) + label,
input:focus + label {
transform: translate(0, 0) scale(1);
cursor: pointer;
}
form p select, form p select.selectField {
width: 195px;
padding: 1px 3px;
}
<form action="">
<div class="field">
<input type="text" name="fullname" id="fullname" placeholder="Jane Appleseed">
<label for="fullname">Name</label>
</div>
<div class="field">
<input type="email" name="email" id="email" placeholder="jane.appleseed#example.com">
<label for="email">Email</label>
</div>
<div id="lettersSelection" >
<p class="required">
<select name="letters" id="letters" class="selectField" required="">
<option value="" selected disabled hidden>Your Letter</option>
<option value="A">Letter A</option>
<option value="B">Letter B</option>
<option value="C">Letter C</option>
</select>
<label for="letters">Letters</label>
</p>
</div>
</form>
This exactly what you asked for.
I've marked the lines in the CSS where changes were made.
I've also added an extra element to the HTML:
<span class="placeholder">Your Letter</span>
body {
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
}
form {
margin: 2em 0;
}
.field {
display: flex;
flex-flow: column-reverse;
margin-bottom: 1em;
}
label{
display: inline-block; /* <--- needed to have display other than default "inline" */
}
label,
input,
.placeholder{ /* <--- added ".placeholder" */
transition: .2s;
touch-action: manipulation;
}
input {
font-size: 1.5em;
border: 0;
border-bottom: 1px solid #ccc;
font-family: inherit;
-webkit-appearance: none;
border-radius: 0;
padding: 0;
cursor: text;
}
input:focus {
outline: 0;
border-bottom: 1px solid #666;
}
label {
text-transform: uppercase;
letter-spacing: 0.05em;
}
input:placeholder-shown+label,
.placeholder { /* <--- added ".placeholder" */
cursor: text;
max-width: 66.66%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transform-origin: left bottom;
transform: translate(0, 2.125rem) scale(1.5);
}
::-webkit-input-placeholder {
opacity: 0;
transition: inherit;
}
input:focus::-webkit-input-placeholder {
opacity: 1;
}
input:not(:placeholder-shown)+label,
input:focus+label {
transform: none; /* <--- changed to "none" to restore defaults */
cursor: pointer;
}
form p select,
form p select.selectField {
width: 195px;
padding: 5px; /* <--- bigger value to cover the placeholder text */
}
/* ------- ADDED ------ */
#lettersSelection{ position:relative; margin-top:3em; }
#lettersSelection .placeholder{
position: absolute;
top: -1.8rem;
left: 0;
}
select{ position:relative; z-index:1; }
select:focus + .placeholder{
transform: none; /* <--- moves the title up on "focus" */
}
<form action="">
<div class="field">
<input type="text" name="fullname" id="fullname" placeholder="Jane Appleseed">
<label for="fullname">Name</label>
</div>
<div class="field">
<input type="email" name="email" id="email" placeholder="jane.appleseed#example.com">
<label for="email">Email</label>
</div>
<div id="lettersSelection">
<p class="required">
<select name="letters" id="letters" class="selectField" required>
<option value="" selected disabled hidden>Your Letter</option>
<option value="A">Letter A</option>
<option value="B">Letter B</option>
<option value="C">Letter C</option>
</select>
<span class="placeholder">Your Letter</span>
<label for="letters">Letters</label>
</p>
</div>
</form>