简体   繁体   English

下拉列表根据内容的宽度变化

[英]drop down list width change depending on the content

I am trying to change the width of a drop down list depending on the content by using javascript. 我试图通过使用javascript根据内容更改下拉列表的宽度。

Example see amazon's drop down list in the first page in search section. 请参见搜索部分首页中的亚马逊下拉列表示例。 http://www.amazon.com/ref=gno_logo http://www.amazon.com/ref=gno_logo

Can anyone help me? 谁能帮我?

Amazon uses another <span> element overlayed on top of the <select> which has its content changed to fit the select menu's value - and it uses width: auto on this tag to fit it to its contents. 亚马逊使用另一个<span>元素覆盖在<select>顶部,其内容已更改为适合select菜单的值-并且它使用width: auto在此标签上使其适合其内容。

So in effect, the drop-down list in Amazon is hidden while a "fake" drop-down in the form of a separate span takes its place. 因此,实际上,隐藏了Amazon的下拉列表,而以单独的span形式的“假”下拉列表代替了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM