I've gone through all the related questions, but unfortunately, I couldn't find a solution. I have shared the code I have so far. My goal is to eliminate the required
attribute from the <select>
element and keep it functioning correctly. If I simply remove it now, the functionality will break.
I am aware that this can be achieved using JavaScript/jQuery, but my preference is to accomplish this with CSS.
label.input {
position: relative;
overflow: hidden;
}
span.input__label {
position: absolute;
left: 0;
padding: 7px 12px;
width: 240px;
font-size: 14px;
color: #828282;
pointer-events: none;
height: 35px;
}
.input:active::after {
transform: rotate(-180deg);
}
.input__field:invalid {
color: transparent;
transition: 200ms color linear 100ms;
}
.input__field:valid + .input__label, .input__field:focus:valid + .input__label {
transform: translate(0.5em, -10%);
transition: 200ms transform ease-out;
color: #000;
top: 5px;
left: 2px;
padding: 0 7px;
font-size: 10px;
}
.input__label {
position: absolute;
left: 0;
top: 0;
right: 0;
padding: 1.5rem 1.5rem 0;
pointer-events: none;
transform-origin: 0 0;
transition: 200ms transform ease-out 200ms;
will-change: transform;
}
select.form-select {
width: 240px;
font-size: 14px;
color: #828282;
display: inline-block;
}
select.form-select option {
color: #828282;
}
.form-select:focus {
border-color: #dcd9d6;
outline: 0;
box-shadow: none;
}
form select {
width: 240px;
height: 52px;
padding: 16px 11px;
font-weight: normal;
font-size: 14px;
color: #828282;
border-radius: 5px;
background: #fff;
border: 1px solid #dcd9d6;
margin-right: 7px;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="64060b0b10171016051424514a544a56">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<label class="input">
<select name="max-price" class="input__field form-select" id="maxPrice" required>
<option value="" selected disabled hidden></option>
<option value="100,000">100,000</option>
<option value="200,000">200,000</option>
<option value="300,000">300,000</option>
</select>
<span class="input__label">Max Price</span>
</label>