tags:

views:

3223

answers:

4

Is there a css only way to style <select> dropdown?

I need to style a form as much as humanly possible without any javascript intervention. What are the properties I can use to do so in CSS?

This code needs to be compatible with all major browsers.IE6,7,8 All FF and safari versions

Edit:

I know i can make it with javascript

http://www.queness.com/post/204/25-jquery-plugins-that-enhance-and-beautify-html-form-elements

and i'm not talking about simple styling. i want to know, what best we can do with css only.

Edit 2:

I found similar questions on SO

http://stackoverflow.com/questions/1072239/is-it-possible-to-style-a-select-box

and this one on Doctype.com

http://doctype.com/style-select

+3  A: 

Yes. You may style any HTML element by its tag name, like this:

select {
  font-weight: bold;
}

Of course, you can also use a CSS class to style it, like any other element:

<select class="important">
  <option>Important Option</option>
  <option>Another Important Option</option>
</select>

<style type="text/css">
  .important {
    font-weight: bold;
  }
</style>
Dave Ward
i'm not talking about like this i want to change dropdown arrow to something else
metal-gear-solid
You can't style the dropdown arrow to another image, it's controlled by the OS. If you really need to, your best bet is to use a DHTML dropdown widget.
Ryan Doherty
You can only change CSS properties through CSS. You can change its margin, padding, font properties, background-color, etc. If you want to make it look completely different, you basically have to replace it with graphics at runtime via JavaScript (which isn't a terrible solution if done well).
Dave Ward
@Ryan Doherty ok
metal-gear-solid
Upvoted for effort
David Caunt
+3  A: 

The select element and its dropdown feature are difficult to style.

This link confirms what Ryan Dohery said in a comment to the first answer.

"The select element is part of the operating system, not the browser chrome. Therefore it is very unreliable to style, and does not necessarily make sense to try anyways."

pavium
+4  A: 

<select> tags can be styled through CSS just like any other HTML element on an HTML page rendered in a browser. Below is an (overly simple) example that will position a select element on the page and render the text of the options in blue.

Example HTML file (selectExample.html):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head>
  <title>Select Styling</title>
  <link href="selectExample.css" rel="stylesheet">
</head>
<body>
<select id="styledSelect" class="blueText">
  <option value="yourMom">Your Mom</option>
  <option value="myMom">My Mom</option>
</select>
</body>
</html>

Example CSS file (selectExample.css):

/* All select elements on page */
select {
  position: relative;
}

/* Style by class. Effects the text of the contained options. */
.blueText {
  color: #0000FF;
}

/* Style by id. Effects position of the select drop down. */
#styledSelect {
  left: 100px;
}
jeremyosborne
A: 
select  {
  outline: 0;
  overflow: hidden;
  height: 30px;
  background: #2c343c;
  color:#747a80;
  border:#2c343c ;
  padding:5px 3px 5px 10px;
  -moz-border-radius:6px;
 -webkit-border-radius:6px;
 border-radius:10px;
}

select option {border:1px solid #000; background:#010;}
gecko