On ne peut pas faire un scroll horizontal dans une Selectbox en html. Cependant, il existe un moyen d'émuler ce type de Selectbox :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 <html> <head> <title>Horizontal scroll bar dans un select box</title> <script language="javascript"> //Scrolling sur DIV function OnDivScroll() { var liste = document.getElementById("liste"); //horizontal scrolling: Pour éviter un scroll vertical quand la taille de la selectbox est 8 et le compte des items est plus grand //vertical scrolling: Pour voir tous les items de la selectbox //Vérifie si les items sont plus que 8, et mettre la taille de la select en conséquence if (liste.options.length > 8) { liste.size=liste.options.length; } else { liste.size=8; } } function OnSelectFocus() { if (document.getElementById("divListe").scrollLeft != 0) { document.getElementById("divListe").scrollLeft = 0; } var liste = document.getElementById('liste'); if( liste.options.length > 8) { liste.focus(); liste.size=8; } } </script> </head> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <table cellpadding="0" cellspacing="0" border="0" align=center> <tr> <td> <asp:Label Runat=server ID="Label2"> Liste :</asp:Label> </td> </tr> <tr> <td> <br> <SELECT size="9" multiple style="WIDTH: 300px"> <OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION> <OPTION>Item 4</OPTION> <OPTION>Item 5</OPTION> <OPTION>Item 6</OPTION> <OPTION>Item 7</OPTION> <OPTION>Item 8</OPTION> <OPTION>Item 9</OPTION> <OPTION>Item 10</OPTION> </SELECT> </td> </tr> <tr> <td> <br> <hr> <br> <asp:Label Runat=server ID="Label1"> Liste :</asp:Label> </td> </tr> <tr> <td> <br> <div id="divListe" style="OVERFLOW: auto;WIDTH: 304px;HEIGHT: 147px" onscroll="OnDivScroll();"> <SELECT id="liste" size="8" multiple onfocus="OnSelectFocus();"> <OPTION>Item 1</OPTION> <OPTION>Item 2</OPTION> <OPTION>Item 3</OPTION> <OPTION>Item 4</OPTION> <OPTION>Item 5</OPTION> <OPTION>Item 6</OPTION> <OPTION>Item 7</OPTION> <OPTION>Item 8</OPTION> <OPTION>Item 9</OPTION> <OPTION>Item 10</OPTION> </SELECT> </div> </td> </tr> </table> </form> </body> </html>
Partager