1

I have created the following drop down list using the

<select></select> 

tags . The code that i used is :

<html> <body> <select name="ans" > <option> select 1</option> <option> select 2</option> </select> </body> </html> 

Is their a way i can change the style of the list , like the drop down arrow or the text in it .

5
  • 1
    You can style is a little bit, but from my experience they are quite hard to style, i think some people use javascript to do it Commented Feb 12, 2013 at 8:18
  • 2
    I'd recommened on using a plugin called jQuery Chosen, enables a better select box and comes with a css that's easily controlled. Commented Feb 12, 2013 at 8:18
  • can anyone show me how i can do it in jQuery . Commented Feb 12, 2013 at 8:20
  • 1
    search for 'jquery select box' Commented Feb 12, 2013 at 8:22
  • stackoverflow.com/questions/14434645/… Commented Feb 12, 2013 at 8:50

1 Answer 1

3

If you want to style the Dropdown-Button you can come up with following approach. The idea is to hide the original select by lowering it's opacity to 0, but still keep its functionality. We also need a little bit JS for this (just a little bit), to change the Text-value when you change the options-value in the select.

The CSS:

.selectWrap { /* Style your own select-box here */ background: #ddd; border: 1px solid black; color: #333; /* Your new Arrow */ /* Created with the after-pseudo-element to save Markup, Styled the arrow with help of the border-trick to provide Retina-ready arrow */ &:after { border-width: 6px; border-style: solid; border-color: transparent transparent transparent #000; content: ""; right: 20px; position: absolute; top: 20px; } height: 30px; position:relative; } /* Hide the original select */ select { height: 30px; left: 0; position: absolute; top: 0; width: 100%; /* Hide the select cross-browser */ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; filter: alpha(opacity=0); -moz-opacity: 0.0; -khtml-opacity: 0.0; opacity: 0.0; } 

The HTML:

<div class="selectWrap"> <select> <option>one</option> <option>two</option> </select> <div class="selectText">Please choose..</div> </div> 

The JavaScript (jQuery):

/* Always when the option in the select is changed, change the text of our selectWrap */ $(document).ready(function () { $('.selectWrap select').on('change', function (e) { var wrap = $(e.target).parents('.selectWrap'); wrap.find('.selectedText').html(this.options[this.selectedIndex].innerHTML); }); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.