简体   繁体   English

防止 select 标签中的文字与背景图片重叠

[英]Prevent text in select tag from overlapping background image

I have a simple select which needs to remain at most 200px in width.我有一个简单的select ,它的200px最多需要保持 200 像素。 The issue I'm having is that the longer text is appearing on top of the background image.我遇到的问题是较长的文本出现在背景图像的顶部。

How can I get it so that the select remains 200px and then, if longer text exists, it will not overlap the dropdown arrow?我怎样才能得到它,以便 select 保持200px ,然后,如果存在更长的文本,它不会与下拉箭头重叠?

 select{ width: 200px; border: 0; background: #fff url(https://f.hubspotusercontent00.net/hubfs/2367000/select_arrow.png/medium.png?t=1592558417346); background-size: 20px; background-repeat: no-repeat; background-position: right 25px center; background-size: 15px; -webkit-appearance: none; -moz-appearance: none; padding: 10px 15px; border: 1px solid #B8B9BA; outline:none; border-radius: 26px; }
 <select> <option>This option here is really long</option> <option>Medium length option</option> <option>short</option> </select>

Simply increase the right padding.只需增加正确的填充即可。

 select{ width: 200px; border: 0; background: #fff url(https://f.hubspotusercontent00.net/hubfs/2367000/select_arrow.png/medium.png?t=1592558417346); background-size: 20px; background-repeat: no-repeat; background-position: right 25px center; background-size: 15px; -webkit-appearance: none; -moz-appearance: none; padding: 10px 50px 10px 15px; border: 1px solid #B8B9BA; outline:none; border-radius: 26px; }
 <select> <option>This option here is really long</option> <option>Medium length option</option> <option>short</option> </select>

You could use the text-overflow:ellipsis;您可以使用text-overflow:ellipsis; property财产

 select{ width: 200px; border: 0; background: #fff url(https://f.hubspotusercontent00.net/hubfs/2367000/select_arrow.png/medium.png?t=1592558417346); background-size: 20px; background-repeat: no-repeat; background-position: right 25px center; background-size: 15px; -webkit-appearance: none; -moz-appearance: none; padding: 10px 15px; border: 1px solid #B8B9BA; outline:none; border-radius: 26px; overflow:hidden; text-overflow:ellipsis; padding-right:40px; }
 <select> <option>This option here is really long</option> <option>Medium length option</option> <option>short</option> </select>

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

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