4

I already searched everywhere for this and haven't find it anywhere. Starting to think it's not doable. My Question is this:

Is it possible to style with CSS, the selected value of a select box?

I'm using this code with the class pretty-select to style the entire select box!

  <div class="pretty-select">
    <select name="city" class="city">
      <option value="Porto" selected="selected">Porto</option>
      <option value="Penafiel">Penafiel</option>
      <option value="Lisboa">Lisboa</option>
      <option value="Madrid">Madrid</option>
      <option value="Barcelona">Barcelona</option>
    </select>
  </div>

Thanks for yout time! Cheers

Afonso Gomes
  • 902
  • 1
  • 14
  • 40
  • 1
    possible duplicate of [HTML – Quentin May 03 '12 at 12:01

2 Answers2

3

Unfortunately what you ask is not possible by using pure CSS. However, here is something similar that you can choose as a work around.

Check the live code http://jsfiddle.net/Etr4F/

HTML:

<div>
Select
<ul>
    <li><a href="#">Item 1</a></li>
    <li><a href="#">Item 2</a></li>
    <li><a href="#">Item 3</a></li>
</ul>
</div>

CSS:

div { 
  margin: 10px;
  padding: 10px; 
  border: 2px solid purple; 
  width: 200px;
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}
div > ul { display: none; }
div:hover > ul {display: block; background: #f9f9f9; border-top: 1px solid purple;}
div:hover > ul > li { padding: 5px; border-bottom: 1px solid #4f4f4f;}
div:hover > ul > li:hover { background: white;}
div:hover > ul > li:hover > a { color: red; }

cheers!!

Roy Sonasish
  • 4,571
  • 20
  • 31
Sandeep Rao
  • 341
  • 3
  • 9
  • 22
1

If you're not adverse to using jQuery UI, you can customise it as much as you like.

http://view.jqueryui.com/selectmenu/demos/selectmenu/default.html

Ollie
  • 646
  • 4
  • 13