Styled Select Fields, Only CSS/HTML
Style select fields without Javascript
by Matthew Schenker
May 02, 2024
HTML
<label>
In This Section<br/>
</p>
<select>
<option selected> Select Box </option>
<option>Short Option</option>
<option>This Is A Much Longer Option that could go over</option>
</select>
</label>
CSS
p {
margin-bottom: 0;
}
select {
padding: 3px;
margin: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
background: #f6f6f6;
color: #999;
border: 1px solid #f6f6f6;
outline: none;
display: inline-block;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
}
/* Targetting Webkit browsers only. FF will show the dropdown arrow with so much padding. */
@media screen and (-webkit-min-device-pixel-ratio:0) {
select {
padding-right: 18px
}
}
label {
position: relative
}
label:after {
content: '<>';
font: 11px "Consolas", monospace;
color: #aaa;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
right: 8px;
top: 2px;
padding: 0 0 2px;
border-bottom: 1px solid #f6f6f6;
position: absolute;
pointer-events: none;
}
label:before {
content: '';
right: 6px;
top: 0px;
width: 20px;
height: 20px;
background: #f6f6f6;
position: absolute;
pointer-events: none;
display: block;
}