html中控制select的宽度

Controlling the width of SELECT lists
= Index DOT Html by Brian Wilson =

Main Index | Element Index | Element Tree | HTML Support History
The Issue | Possible Solutions | Recommendation



The Issue
The default width of a SELECT form control is usually dependent on the width of the widest OPTION item in the list; the width of the SELECT list will basically be not much greater (but no less) than this width.

The HTML standards don't allow for a way to control this width. CSS, on the other hand, would be perfect for controlling this, but historical support for CSS on form controls is rather weak.

Solution 1: Using   to pad OPTION element content
Support Key: [IE1|M2A1|N1|O2.1]
This solution can work rather well - non-breaking spaces are treated as displayable content, so these can be used to add crude right and left "padding" widths to the SELECT control. The one downside of this method is that it is difficult to achieve a precise width for the control.

Solution 2: Using a WIDTH attribute on the SELECT control
Support Key: [IE|M|N4-4.x|O]
This proprietary attribute was added in Netscape 4.x, and has been retired in Netscape 6.x, but this attribute takes as a value a positive integer representing a pixel width for the control. The disadvantage here is that only Netscape 4.x supports it.

Solution 3: CSS on the SELECT control
Support Key: [IE4|M|N6B1|O5]
This is by far the best solution, using the 'width' CSS property - and it has the widest support.

Recommendation

Since Netscape 4 has only the proprietary attribute that will give the desired effect, it will not hurt anything to combine the use of CSS and the WIDTH attribute.

Example
< select NAME="foo" WIDTH="300" STYLE=" width: 300px">
    < option>one
    < option>two
    < option>three
</ select>

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值