Skip to content

Instantly share code, notes, and snippets.

@jpsirois
Created August 21, 2012 19:18
Show Gist options
  • Save jpsirois/3418477 to your computer and use it in GitHub Desktop.
Save jpsirois/3418477 to your computer and use it in GitHub Desktop.
Dead Simple CSS Only Custom-Select (fallback to standard <select> for IE7 and below)
<!DOCTYPE html>
<!--[if lt IE 8]><html class="lt-ie8" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--><html lang="en"><!--<![endif]-->
<head>
<meta charset="UTF-8" />
<title>Dead Simple Cross-Browser Custom-Select</title>
<style>
body {
margin: 20px;
}
#styled-select {
width: 240px;
height: 34px;
overflow: hidden;
background: lightblue;
border: 1px solid #ccc;
}
#styled-select select {
background: transparent;
width: 264px;
padding: 5px;
font-size: 16px;
border: 0;
height: 34px;
display: inline-block;
-webkit-appearance: none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
}
.lt-ie8 #styled-select {
width: auto;
height: auto;
overflow: auto;
background: none;
border: 0;
}
.lt-ie8 #styled-select select {
background: auto;
width: 240px;
}
</style>
</head>
<body>
<div id="styled-select">
<select>
<option>Value 1</option>
<option>Value 2</option>
<option>Value 3</option>
<option>Value 4</option>
<option>Value 5</option>
</select>
</div>
</body>
</html>
@jpsirois
Copy link
Author

@mikaelz
Copy link

mikaelz commented May 22, 2013

Thanks, the preview didn't work so I made another http://nevilleweb.sk/testing/custom-select-fallback.html :)

I'm using jQuery selectbox

CSS:
select {visibility: hidden}

HTML, before </head>:
<noscript><style>select {visibility: visible}</style></noscript>

Copy link

ghost commented Feb 13, 2014

Thank you so much!

@chrisjlee
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment