Mobile-analog drop-down list

Source: Internet
Author: User

Using native drop-down lists (select) on the mobile side will have their own style, what do you want to do with a custom style?

The first step is to get rid of the default style:-webkit-appearance:none; These types of properties under input, such as type= "date", will remove the default style, but this time the border of the select setting, Styles, such as width or text centering, do not work. This is the time to simulate the Select box. The select tag is still used because select uses the default bullet box on the mobile side.

Final effect

The HTML structure is as follows:

1 <Divclass= "Select-area">2     <spanclass= "Select-value"></span>3     <Select>4        <option>Gansu</option>5        <option>Lanzhou</option>6     </Select>7 </Div>

Select-value is used to store the value of the dropdown box selected, hide Select, and then use JS to control the value of the drop-down box displayed.

the corresponding styles are as follows:
1 . Select-area{2 position:relative;3 Overflow:Hidden;4}5 . Select-area Select{6 position:Absolute;7  Left:0;8 Top:0;9 Opacity:0;Ten width:100%; One}

The next step is to use JS to control the display of the selected values:

1$ (". Select-area. Select-value"). each (function(){2                 if( $( This). Next ("select"). Find ("option:selected"). Length! = 0 ){3$( This). Text ($ ( This). Next ("select"). Find ("option:selected")). text ());4                 }5             });6$ (". Select-area select"). Change (function(){7                 varValue = $ ( This). Find ("option:selected"). text ();8$( This). Parent (". Select-area"). Find (". Select-value")). Text (value);9});

The end result is the effect on the phone as shown.

Mobile-analog drop-down list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.