HTML <option> tag tooltip

北城余情 提交于 2019-12-23 19:05:29

问题


I have a tag with many child nodes. I want to keep the width of this drop-down list to a minimum size. However, there are times when the innerHTML of at least one option is very long, forcing the drop-down list box to expand its width.

What I'm planning to do is to truncate the long text and use ellipses to denote that some characters have been truncated ("very loooooong sentence" becomes "very loooooo.."). In order to show the full text, I'm thinking of using tooltip message on mouse over event.

Unfortunately, the onmouseover event for each tag doesn't seem to work. What can I do to achieve this effect?

Thanks


回答1:


Adding a title attribute to each option should do the trick.

<option value="1" title="Long description">Short desc...</option>



回答2:


You can set the width of the <select> and the dropdown will extend beyond the width of the select. Try the following:

<select style="width: 30px">
  <option>1</option>
  <option>really long</option>
  <option>even more longer</option>
  <option>This should be long enough to stretch to the end of the page, but the select is still not very long</option>
</select>


来源:https://stackoverflow.com/questions/2205733/html-option-tag-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!