How to style select option with css -
i need style select css, looks image below, there 2 things cant figure out, when option selected remove classic blue background, how indent text, text-indent not working me, , how lower option box.
<select name="txtcountry"> <option>select country</option> <option value="1">georgia</option> <option value="2">afghanistan</option> </select>
select
tags near-enough impossible customise, , @ mercy of browser how styled (albeit height , width).
you better construct , style own using css if looking customisable option in cross-browser compatible.
i have used jquery in order complete functionality. makes use of spans in order replace option
tags, allowing further styling (no external library needed, although there many available):
$('.item').hide(); $('.item').click(function () { var x = $(this).text(); $(this).siblings(".selected").text(x); $(this).slideup().siblings(".item").slideup(); }); $('.drop').click(function () { $(this).parent().toggleclass("opened"); $(this).siblings(".item").slidetoggle(); }); $('.selected').click(function () { $(this).parent().removeclass("opened"); $(this).siblings(".item").slideup(); });
div { height:30px; width:200px; background:lightgray; position:relative; } .item, .selected { display:block; height:30px; width:100%;position:relative; background:gray; transition:all 0.6s; line-height:30px; } .selected { background:none; display:block; } .item:hover { background:lightgray; } .drop { position:absolute; top:0; right:0; height:100%; width:30px; background:tomato; transition:all 0.4s; transform:rotate(0deg); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <span class="selected">1</span> <span class="drop"></span> <span class="item">1</span> <span class="item">2</span> <span class="item">3</span> <span class="item">4</span> <span class="item">5</span> <span class="item">6</span> </div>
note
this not finished product, demo only.
Comments
Post a Comment