【问题标题】:Apply a style to a select box, why doesn't it work?将样式应用于选择框,为什么它不起作用?
【发布时间】:2011-11-01 11:08:23
【问题描述】:

我想给一个选择框设置一个样式,我尝试了下面的代码,但问题是标签选项中的less和rise字母,它不会改变宽度样式选择框并且它是固定的。 'width="auto"' 怎么做呢?

演示: http://jsfiddle.net/uG3gq/

<div class="select_box" style="margin: 10px 5px 0 5px;">
    <select name="type_star">
        <option disabled="disabled" value="">Select</option>
        <option>Ttttttttttttttttttttt</option>
        <option>Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option>
        <option>B</option>
        <option>C</option>
    </select>
</div>

.select_box {
    overflow:hidden;
    background:url(http://img4up.com/up2/17845058228414984898.png) no-repeat right #9ff;
    height:24px;
    font:13px Tahoma,Arial,Helvetica,Sans-serif;
    color:#888888;
    padding:0;
}
.select_box select {
    background:transparent;
    padding:0 0 0 0;
    border:1px soild #666;
    font-size:16px;
    color:#888888;
    height:26px;
    -webkit-appearance:none;
    outline: none;
}

【问题讨论】:

    标签: html css


    【解决方案1】:

    您可以保留它而不设置显式宽度,让浏览器自动处理宽度。在这种情况下,浏览器将确定最长的选项并据此设置选择元素的宽度。或者您可以将其设置为像 width=200px; 这样的宽度,这将给出一个明确的宽度。

    除非您想编写一些 Javascript 来确定最长选项并动态设置宽度,否则我认为这是不可能的(AFAIK)

    【讨论】:

    猜你喜欢
    • 2016-01-14
    • 1970-01-01
    • 2014-01-29
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    相关资源
    最近更新 更多