I am using the CSS found here to make floating form labels. I chose this styling because there is no JavaScript needed and the HTML markup is simple enough (i.e. a div with a class and then only a label and input tag). If there are other simple style sheets available please let me know.
I am a backend developer and I suck at CSS and cannot figure out how to adjust this CSS so it looks nice when:
There is a select tag (<select/> instead of an <input/> tag)
When the background is not white
Any help will be greatly appreciated!
<form class="float-label" spellcheck="false">
<legend>Float Label Demo</legend>
<!-- we need a wrapping element for positioning the label -->
<!-- the required attribute is ... required! -->
<div class="control">
<input type="text" name="title" placeholder="Title" required />
<!-- yes, this is not nice, in real live, do it with JS -->
<label for="title">Title</label>
</div>
<div class="control small">
<input type="text" name="price" placeholder="Price" required />
<label for="price">Price</label>
</div>
<div class="control medium">
<input type="text" name="location" placeholder="Specific location (optional)" required />
<label for="location">Specific location (optional)</label>
</div>
<div class="control">
<textarea name="description" placeholder="Description" required></textarea>
<label for="description">Description</label>
</div>
</form>
#border: 1px solid #ddd;
#padding: 10px;
#label-font-size: 13px;
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
width: 100%;
min-height: 300px;
}
// Demo styles
form {
width: 600px;
margin: 2em auto;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 300;
font-size: 22px;
legend {
font-size: 2em;
margin-bottom: 1em;
width: 100%;
border-bottom: #border;
}
}
// float label
.float-label {
.control {
float: left;
position: relative;
width: 100%;
border-bottom: #border;
padding-top: #padding + #label-font-size;
padding-bottom: #padding;
// you proably want to replace these with your grid classes
&.small {
width: 30%;
border-right: #border;
}
&.medium {
width: 70%;
padding-left: #padding;
}
&:last-child {
border: 0;
}
}
input, textarea {
display: block;
width: 100%;
border: 0;
outline: 0;
resize: none;
// inactive but shown label (exceptions: opacity and top)
& + label {
position: absolute;
top: 10px;
transition: top 0.7s ease, opacity 0.7s ease;
opacity: 0;
// Some nice styling
font-size: #label-font-size;
font-weight: 600;
color: #ccc;
}
// THE MAGIC
// as soon as we start typing, the "required" attribute will
// set the state to valid and our pseudo selector will match
&:valid + label {
opacity: 1;
top: 3px;
}
// and we highlight the focused input label
&:focus + label {
color: #2c8efe;
}
}
}
Here is what this styling looks like when the background is black:
You've copied the Less (non-compiled CSS) which will not render properly in browsers - so if you take examples from CodePen in the future keep that in mind :)
The inputs have a transparent background, which lends itself to any background colour ( or pattern ) so if you change the background colour of the body/parent it will still look good
This might be what you're looking for:
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
width: 100%;
min-height: 300px;
background-color: #000;
}
form {
width: 600px;
margin: 2em auto;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 300;
font-size: 22px;
}
form legend {
font-size: 2em;
margin-bottom: 1em;
width: 100%;
border-bottom: 1px solid #333;
}
.float-label .control {
float: left;
position: relative;
width: 100%;
border-bottom: 1px solid #333;
padding-top: 23px;
padding-bottom: 10px;
}
.float-label .control.small {
width: 30%;
border-right: 1px solid #333;
}
.float-label .control.medium {
width: 70%;
padding-left: 10px;
}
.float-label .control:last-child {
border: 0;
}
.float-label select,
.float-label input,
.float-label textarea {
display: block;
width: 100%;
border: 0;
outline: 0;
resize: none;
background: transparent;
color: #fff;
}
.float-label select + label,
.float-label input + label,
.float-label textarea + label {
position: absolute;
top: 10px;
transition: top 0.7s ease, opacity 0.7s ease;
opacity: 0;
font-size: 13px;
font-weight: 600;
color: #ccc;
}
.float-label select:focus + label,
.float-label input:valid + label,
.float-label textarea:valid + label {
opacity: 1;
top: 3px;
}
.float-label select:focus + label,
.float-label input:focus + label,
.float-label textarea:focus + label {
color: #ccc;
}
<form class="float-label" spellcheck="false">
<legend>Float Label Demo</legend>
<!-- we need a wrapping element for positioning the label -->
<!-- the required attribute is ... required! -->
<div class="control">
<input type="text" name="title" placeholder="Title" required />
<!-- yes, this is not nice, in real live, do it with JS -->
<label for="title">Title</label>
</div>
<div class="control small">
<input type="text" name="price" placeholder="Price" required />
<label for="price">Price</label>
</div>
<div class="control medium">
<input type="text" name="location" placeholder="Specific location (optional)" required />
<label for="location">Specific location (optional)</label>
</div>
<div class="control">
<select>
<option>option 1</option>
<option>option 2</option>
</select>
<label for="description">Description</label>
</div>
</form>
Have a look
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
width: 100%;
min-height: 300px;
background-color: #000;
}
form {
width: 600px;
margin: 2em auto;
font-family: 'Source Sans Pro', sans-serif;
font-weight: 300;
font-size: 22px;
}
form legend {
font-size: 2em;
margin-bottom: 1em;
width: 100%;
border-bottom: 1px solid #333;
}
.float-label .control {
float: left;
position: relative;
width: 100%;
border-bottom: 1px solid #333;
padding-top: 23px;
padding-bottom: 10px;
}
.float-label .control.small {
width: 30%;
border-right: 1px solid #333;
}
.float-label .control.medium {
width: 70%;
padding-left: 10px;
}
.float-label .control:last-child {
border: 0;
}
.float-label select,
.float-label input,
.float-label textarea {
display: block;
width: 100%;
border: 0;
outline: 0;
resize: none;
background: transparent;
color: #fff;
}
.float-label select + label,
.float-label input + label,
.float-label textarea + label {
position: absolute;
top: 10px;
transition: top 0.7s ease, opacity 0.7s ease;
opacity: 0;
font-size: 13px;
font-weight: 600;
color: #ccc;
}
.float-label select:focus + label,
.float-label input:valid + label,
.float-label textarea:valid + label {
opacity: 1;
top: 3px;
}
.float-label select:focus + label,
.float-label input:focus + label,
.float-label textarea:focus + label {
color: #ccc;
}
option{color:#000;}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:active,
input:-webkit-autofill:focus {
-webkit-box-shadow: 0 0 0 1000px #000 inset !important;
-webkit-text-fill-color: #ccc !important;
}
<form class="float-label" spellcheck="false">
<legend>Float Label Demo</legend>
<!-- we need a wrapping element for positioning the label -->
<!-- the required attribute is ... required! -->
<div class="control">
<input type="text" name="title" placeholder="Title" required />
<!-- yes, this is not nice, in real live, do it with JS -->
<label for="title">Title</label>
</div>
<div class="control small">
<input type="text" name="price" placeholder="Price" required />
<label for="price">Price</label>
</div>
<div class="control medium">
<input type="text" name="location" placeholder="Specific location (optional)" required />
<label for="location">Specific location (optional)</label>
</div>
<div class="control">
<select>
<option>option 1</option>
<option>option 2</option>
</select>
<label for="description">Description</label>
</div>
</form>
Add this code to your stylesheet :
.float-label select,
.float-label input,
.float-label textarea {
background: transparent;
}
And you will get the <input>, <textarea>and <select> with transparent background. So you can change the background color to the color of your choice later without any tension about form field background colors.
Thanks Nabeel
A simple answer is to change the background-color of the inputs directly.
Something like this;
input { background-color: blue;}
you could copy/paste that right into your CSS and use any color you want. I put this CSS into the following html code at W3schools.com and got this:
<!DOCTYPE html>
<html>
<body>
<form action="">
User name:
<br>
<style>
input {
background-color: blue;
}
</style>
<input type="text" name="userid">
<br>User password:
<br>
<input type="password" name="psw">
</form>
<p>The characters in a password field are masked (shown as asterisks or circles).</p>
</body>
</html>
I hope this works for you!
Related
I want to create a cool animation that when the user clicks on the email input or the password the label of the input will go up and have a nice transition in the bottom border.
This is what I have:
And this is what I want to create:
My code:
.form {
position: relative;
display: flex;
flex-direction: column;
margin-bottom: 1rem;
}
.input {
background: none;
color: #c6c6c6;
font-size: 1.8rem;
padding: 1.6rem;
display: block;
border: none;
border-bottom: 1px solid #c6c6c6;
width: 100%;
}
.label {
position: absolute;
color: #c6c6c6;
font-size: 1.6rem;
left: 0.5rem;
top: 1rem;
}
<div class="form">
<input class="email input" type="email" name="email" />
<label class="label" for="email">Email Address</label>
</div>
<div class="form">
<input class="password input" type="password" name="password" />
<label class="label" for="password">Password</label>
</div>
I've searched a lot but every code example I found was with SCCS, SASS and I don't understand it. So please help me with plain CSS. Any help would be greatly appreciated!
I created an animated demo using HTML and CSS.
.main {
width: 500px;
margin: 50px 100px;
;
}
.form-group {
position: relative;
margin-bottom: 45px;
}
input {
display: block;
width: 300px;
font-size: 14pt;
padding: 10px;
border: none;
border-bottom: 1px solid #ccc;
}
input:focus {
outline: none;
}
label {
position: absolute;
top: 10px;
left: 5px;
color: #999;
font-size: 14pt;
font-weight: normal;
pointer-events: none;
transition: all 0.2s ease;
}
input:focus ~ label,
input:valid ~ label {
top: -20px;
font-size: 10pt;
color: #5264AE;
}
.bar {
display: block;
position: relative;
width: 320px;
}
.bar:before,
.bar:after {
content: "";
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: #5264AE;
transition: all 0.2s ease;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
input:focus ~ .bar:before,
input:focus ~ .bar:after {
width: 50%;
}
<div class="main">
<div class="form-group">
<input type="text" name="email" required />
<span class="highlight"></span>
<span class="bar"></span>
<label for="email">Email</label>
</div>
<div class="form-group">
<input type="password" name="password" required />
<span class="highlight"></span>
<span class="bar"></span>
<label for="password">Password</label>
</div>
</div>
I attached your code modified to work as intended, you can change any value to customize as you want but here's an explanation of how it works:
Input element
I added a z-index so that the user can click where the label is positioned and click the input instead of the label itself, also added a transition to make the animation smooth.
input:focus refers when input is active (user click or selected by pressing tab key).
And here's where the magic happens and the explanations of complex selectors:
.input:focus~.label,
.input:not([value=""]):not(:focus):invalid~.label,
.input.has-content~.label {
font-size: .7rem;
top: -.4rem;
color: blue;
}
.input:focus ~ .label selects all input's element siblings with the class .label when input is focus so that when user focus in the input the label'll be above.
.input:not([value=""]):not(:focus):invalid~.label this selector'll catch when user unfocus the input but it got content, so the label don't goes down and overlap with the username. (as the password type input doesn't have value attribute I attach you a Js snippet that do the same trick for password element, simply adding the class has-content to the element)
Hope it helps you!
document.querySelector('.password').oninput = (e) => {
e.target.value.length > 0 ?
e.target.classList.add('has-content') :
e.target.classList.remove('has-content')
}
.form {
position: relative;
display: flex;
flex-direction: column;
margin: 1rem;
}
.input {
height: 20px;
background: none;
color: #c6c6c6;
font-size: 1rem;
padding: .5rem .7rem;
display: block;
border: none;
border-bottom: 2px solid #c6c6c6;
width: 100%;
z-index: 2;
transition: all .3s ease;
}
.input:focus {
outline: transparent;
border-color: blue;
}
.input:focus~.label,
.input:not([value=""]):not(:focus):invalid~.label,
.input.has-content~.label {
font-size: .7rem;
top: -.4rem;
color: blue;
}
.label {
position: absolute;
color: #c6c6c6;
font-size: 1rem;
left: 0.5rem;
top: .6rem;
transition: all .3s ease;
}
<div class="form">
<input class="email input" type="email" name="email" />
<label class="label" for="email">Email Address</label>
</div>
<div class="form">
<input class="password input" type="password" name="password" />
<label class="label" for="password">Password</label>
</div>
I want to display my radio buttons as so that i can give style sheet and make div clickable.
here are my radio buttons.
and I want to show them like this.
div as radio
This is what I have tried but did not work.
HTML
<div class="radio-toolbar">
<table>
<tr>
<td><input type="radio" id="radioone" name="product" value="first">
<label for="radioone">50</label></td>
<td><input type="radio" id="radiotwo" name="product" value="second">
<label for="radiotwo">100</label></td>
<td><input type="radio" id="radiothree" name="product" value="third">
<label for="radiothree">500</label></td>
</div>
CSS
.radio-toolbar input[type='radio']:focus + label {
border: 2px thin blue;
}
.radio-toolbar input[type='radio']:checked + label {
background-color: #86b1f7;
border-color: #4c4;
color: white;
}
So how can I achive this
Small help will be appreciated.
Thanks in advance :)
I had do this before.and I have the code preperd.I hope It will be useful for you.
.switch-field {
display: flex;
overflow: hidden;
direction: ltr;
float: right;
text-align:right;
}
.switch-field input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}
.switch-field label {
/*width: 33.33%;*/
background-color: transparent;
color: #666666;
font-size: 14px;
line-height: 1;
text-align: center;
padding: 10px 12px;
margin-left: 0px;
/*margin-right: -1px;*/
border: 1px solid #ddd;
transition: all 0.1s ease-in-out;
}
.switch-field label:hover {
cursor: pointer;
}
.switch-field input:checked + label {
background-color: #F4F5F9;
box-shadow: none;
border-color: #3E7DE7;
color: #3E7DE7;
}
.switch-field label:first-of-type {
border-radius: 2px 0px 0px 2px;
}
.switch-field label:last-of-type {
border-radius: 0px 2px 2px 0px;
}
<div class="switch-field">
<input class="uk-radio" id="radio-six" type="radio" value="admin" name="user_type" checked>
<label for="radio-six">admin</label>
<input class="uk-radio" id="radio-seven" type="radio" value="user" name="user_type" >
<label for="radio-seven">user</label>
</div>
Here is one way you can customize your radio buttons.
.radio-toolbar .radio-item {
position: relative;
display: inline-block;
vertical-align: top;
margin: 15px 5px;
}
.radio-item input[type="radio"] {
position: absolute;
width: 0;
height: 0;
top: 0;
left: 0;
}
.radio-item label {
padding: 10px;
color: #fff;
border-radius: 10px;
background-color: grey;
border: 1px solid #000;
}
.radio-item input[type="radio"]:checked ~ label {
border-color: #f00;
}
<div class="radio-toolbar">
<div class="radio-item">
<input type="radio" id="radioone" name="product" value="first">
<label for="radioone">50</label>
</div>
<div class="radio-item">
<input type="radio" id="radiotwo" name="product" value="second">
<label for="radiotwo">100</label>
</div>
<div class="radio-item">
<input type="radio" id="radiothree" name="product" value="third">
<label for="radiothree">500</label>
</div>
</div>
Please let me know if this helps.
You need to hide the radio buttons and the left over label is still "clickable"
.radio-toolbar input[type="radio"] {
display: none;
}
I put all the working code on codepen here: https://codepen.io/stormingorman-the-vuer/pen/ExjKRvz
Try Like This. Make Your radio-toolbar input, width: 0;
also make your radio-toolbar label Like this
.radio-toolbar label {
background-color: #A9A9A9;
padding: 10px 20px;
font-size: 16px;
border-radius: 4px;
}
I want to design following material design input form using css and bootstrap. Following code is I am currently using. But it doesn't provide exact result I want.
Code Pen Link : View Source Code Here
HTML CODE :
<div class="container">
<h2>Google Material Design in CSS3<small>Inputs</small></h2>
<form>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
</form>
<p class="footer">
a tutorial by scotch.io
</p>
</div>
But I want this design :
CSS Only solution; use combination of sibling selector ~ on the label and :valid pseudo selector on the input.
body {
margin: 10px;
}
.form-group>label {
bottom: 34px;
left: 15px;
position: relative;
background-color: white;
padding: 0px 5px 0px 5px;
font-size: 1.1em;
transition: 0.2s;
pointer-events: none;
}
.form-control:focus~label {
bottom: 55px;
}
.form-control:valid~label {
bottom: 55px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-6">
<br>
<div class="form-group">
<input type="text" class="form-control" id="usr" required>
<label for="usr">Name</label>
</div>
<div class="form-group">
<input type="text" class="form-control" id="password" required>
<label for="usr">Password</label>
</div>
</div>
</div>
</div>
Since you've tagged Bootstrap 4, I'm assuming you wanted the solution with regards to that framework.
Setup a default form-group, label, and input markup like this;
<div class="form-group">
<label for="usr">Name:</label>
<input type="text" class="form-control" id="usr">
</div>
Then add this css, what this would do is
position label relative to its container (form-group)
then we specified the top and left positions so that it would land
on top of the input field
I added a white background and padding to the label so that it would have a box around the label.
.form-group > label {
top: 18px;
left: 6px;
position: relative;
background-color: white;
padding: 0px 5px 0px 5px;
font-size: 0.9em;
}
Here's a fiddle with that code on bootstrap 4;
http://jsfiddle.net/rw29jot4/
For the animation, check this fiddle, we need to utilize click events and move the position of the label;
Updated code with animation;
http://jsfiddle.net/sedvo037/
EDIT: Please see my answer below which uses only CSS.
Try with this code.
HTML:
<div class="main_div">
<div class="group">
<input type="text" required="required"/>
<label>Name</label>
</div>
</div>
CSS:
.main_div{
padding: 30px;
}
input,
textarea {
background: none;
color: #c6c6c6;
font-size: 18px;
padding: 10px 10px 10px 15px;
display: block;
width: 320px;
border: none;
border-radius: 10px;
border: 1px solid #c6c6c6;
}
input:hover{
border: 3px solid black;
}
input:focus,
textarea:focus {
outline: none;
border: 3px solid black;
}
input:focus ~ label, input:valid ~ label,
textarea:focus ~ label,
textarea:valid ~ label {
top: -5px;
font-size: 12px;
color: #000;
left: 11px;
}
input:focus ~ .bar:before,
textarea:focus ~ .bar:before {
width: 320px;
}
input[type="password"] {
letter-spacing: 0.3em;
}
.group{
position: relative;
}
label {
color: #c6c6c6;
font-size: 16px;
font-weight: normal;
position: absolute;
pointer-events: none;
left: 15px;
top: 12px;
transition: 300ms ease all;
background-color: #fff;
padding: 0 2px;
}
Its very simply and I have looked at all these examples but still am not able to figure out what I am doing wrong!
I have created a custom checkbox, increased the size and style, and when it is clicked I want the letter "A" to appear in the box, but it simply will not respond, maybe a second pair of eyes will help me identify the problem.
below is my html and css:
.container {
position: relative;
cursor: pointer;
display: block;
input,
label {
display: inline-block;
}
input {
// opacity: 0;
position: absolute;
height: unset;
width: unset;
cursor: pointer;
}
label::before {
border: 1px solid #333;
content: "";
display: inline-block;
font: 16px/1em sans-serif;
height: 50px;
margin: 0 .25em 0 0;
padding: 0;
vertical-align: top;
width: 50px;
border-radius: 5px;
color: red;
font-size: 50px;
padding: 10px;
}
input[type="checkbox"]:checked + label::before {
content: "A"; //code for checked
}
}
<div class="container">
<div>
<label for="form_agreeTerms" class="required">Agree terms</label>
<input type="checkbox" id="form_agreeTerms" name="form[agreeTerms]" required="required" value="1">
</div>
</div>
Here it is in codepen
You using the + operator, which means "The next sibling element".
You must move the label to be after the checkbox.
<div class="container">
<div>
<input type="checkbox" id="form_agreeTerms" name="form[agreeTerms]" required="required" value="1">
<label for="form_agreeTerms" class="required">Agree terms</label>
</div>
</div>
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>