【问题标题】:Select dropdown Option content wrap not working选择下拉选项内容包装不起作用
【发布时间】:2018-03-30 05:07:48
【问题描述】:

选择dropdown 换行不起作用,我使用了:

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap; 

但没有结果。任何人都可以帮助解决这个问题

<div style="width: 200px;">
<select  style="width: 200px;">
  <option value="">Volvo</option>
  <option value="">You already have a live sesstion of this application open.Yoy can only have one session of this application in this webpage at a time.</option>
  <option value="">Mercedes</option>
  <option value="">Audi</option>
</select>
</div>

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

您不能将换行符格式化为选项;但是,您可以使用 title 属性提供鼠标悬停工具提示以提供完整信息。在选项文本中使用简短的描述符,并在标题中使用完整的字眼。

<option value="1" title="This is my lengthy explanation of what this selection really means, so since you only see 1 on the drop down list you really know that you're opting to elect me as King of Willywarts!  Always be sure to read the fine print!">1</option>

<div style="width: 200px;">
<select  style="width: 200px;">
  <option value="">Volvo</option>
  <option value="">You already have a live sesstion of this application open.Yoy can only have one session of this application in this webpage at a time.</option>
  <option value="">Mercedes</option>
  <option value="">Audi</option>
  <option value="1" title="This is my lengthy explanation of what this selection really means, so since you only see 1 on the drop down list you really know that you're opting to elect me as King of Willywarts!  Always be sure to read the fine print!">1</option>
</select>
</div>

【讨论】:

    【解决方案2】:

    你不能那样做。通常选项不能是样式。所以你可以像这样使用jquery

    $('option').each(function(){
    			var text=$(this).text()
    			$(this).val(text).text(text.substr(0,50)+'…')
    		})
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div style="width: 200px;">
    <select  style="width: 200px;">
      <option value="">Volvo</option>
      <option value="">You already have a live sesstion of this application open.Yoy can only have one session of this application in this webpage at a time.</option>
      <option value="">Mercedes</option>
      <option value="">Audi</option>
    </select>
    </div>

    我给了text.substr(0,50)你可以改。

    【讨论】:

    • 感谢您的解决方案,但我的客户不接受此解决方案,他希望将文本包装到第二行任何替代解决方案
    猜你喜欢
    • 2018-05-20
    • 2014-07-04
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2018-04-17
    相关资源
    最近更新 更多