Implement the selec drop-down box through css simulation and the cssselec drop-down box

Source: Internet
Author: User

Implement the selec drop-down box through css simulation and the cssselec drop-down box

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> drop-down list </title>
<Style>
*{
Margin: 0;
Padding: 0;
}

Body {
Padding: 50px 50px;
}

. Btn-select {
Position: relative;
Display: inline-block;
Width: 150px;
Height: 25px;
Background-color: # f80;
Font: 14px/20px "Microsoft YaHei ";
Color: # fff;
}

. Btn-select. cur-select {
Position: absolute;
Display: block;
Width: 150px;
Height: 25px;
Line-height: 25px;
Background: # f80 url(ico-arrow.png) no-repeat 125px center;
Text-indent: 10px;
}

. Btn-select: hover. cur-select {
Background-color: # f90;
}

. Btn-select {
Position: absolute;
Top: 0;
Left: 0;
Width: 150px;
Height: 25px;
Opacity: 0;
Filter: alpha (opacity: 0 ;);
Font: 14px/20px "Microsoft YaHei ";
Color: # f80;
}

. Btn-select option {
Text-indent: 10px;
}

. Btn-select option: hover {
Background-color: # f80;
Color: # fff;
}
</Style>
</Head>

<Body>
<Form>
<A class = "btn-select" id = "btn_select">
<Span class = "cur-select"> select </span>
<Select>
<Option> option 1 </option>
<Option> option 2 </option>
<Option> option 3 </option>
<Option> option 4 </option>
<Option> option 5 </option>
</Select>
</A>
</Form>

<Script>
Var $ = function (id ){
Return document. getElementById (id );
}
Window. onload = function (){
Var btnSelect =$ $ ("btn_select ");
Var curSelect = btnSelect. getElementsByTagName ("span") [0];
Var oSelect = btnSelect. getElementsByTagName ("select") [0];
Var aOption = btnSelect. getElementsByTagName ("option ");
OSelect. onchange = function (){
Var text = oSelect. options [oSelect. selectedIndex]. text;
CurSelect. innerHTML = text;
}
}
</Script>
</Body>
</Html>


How can the select drop-down box in css be made into a horizontal row?

Hello! This is implemented with css + js. The reference code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> select the ABCDEFGHI_select horizontal row effect </title>
</Head>
<Body>
<Style>
* {Font-size: 12px ;}
A. s_l {
BORDER: # dddddd 1px solid; BORDER-right: # dddddddd 0px solid; BACKGROUND: # ffffff; PADDING: 4px 6px 2px 6px; TEXT-DECORATION: none; line-height: 12px
}
A. s_l: hover {
BORDER: #003366 1px solid; BORDER-right: # dddddd 0px solid; BACKGROUND: # 0063dc; COLOR: # ffffff; TEXT-DECORATION: none; line-height: 12px
}
A. s_r {
BORDER: # dddddd 1px solid; BACKGROUND: # ffffff; PADDING: 4px 6px 2px 6px; TEXT-DECORATION: none; line-height: 12px
}
A. s_r: hover {
BORDER: #003366 1px solid; BACKGROUND: # 0063dc; COLOR: # ffffff; TEXT-DECORATION: none; line-height: 12px
}
Input {BORDER: # aaa 1px solid; width: 65px; height: 23px; PADDING: 4px 6px 0px 6px; background: url (images/a.jpg) no-repeat 95% center ;}
. Span1 {position: relative; top: 3px ;}
. Span2 {position: relative; left:-3px; top: 1px}
</Style>
<Span class = "span1"> <input type = "text" value = "select" onclick = "sele (this)"> </span>
<Span class = "span2" id = "select" style = "display: none"> <A class = s_l
Href = "###"> A </A> <A class = s_l
Href = "###"> B </A> <A class = s_l
Href = "###"> C </A> & l ...... remaining full text>

How does div + css implement the drop-down box? Such? Can it be simulated by js? How can this problem be solved? Solution

The drop-down box cannot be controlled by css. The effect is actually the background image used in a div, the option is displayed by li, and the display effect is controlled by js.

Related Article

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.