欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
默认情况下,<select>元素的大小取决于最大<option>文本的大小。但是,有时当用户尝试选择某个选项(即聚焦)时,将固定宽度设置为选择框并将其大小增加回原始大小会很有用。
 
以下示例演示了如何使用纯CSS实现此效果:
 
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Increase Select Box Size on Focus</title>
<style>
    select {
        width: 150px;
        margin: 10px;
    }
    select:focus {
        min-width: 150px;
        width: auto;
    }
</style>
</head>
<body>
    <form>
        <select>
            <option>Choose</option>
            <option>This option is large</option>
            <option>This option is very large</option>
            <option>This option is very very large</option>
            <option>This option is very very very large</option>
        </select>
    </form>
</body>
</html>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h61099.shtml