html - 防止选择标签中的文本与背景图像重叠

标签 html css

我有一个简单的 select 需要保持最多 200px 的宽度。我遇到的问题是较长的文本出现在背景图像的顶部。

我怎样才能让选择保持 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>

最佳答案

只需增加右边的内边距。

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>

关于html - 防止选择标签中的文本与背景图像重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62951440/

相关文章:

javascript - 将json数据转换为html表

javascript - 如何随机化段落中的字间距?

javascript - 条件形式取决于选择列表中的答案不起作用

javascript - 在上一个函数完成后执行函数

html - IE6 错误!侧面板

javascript - CSS FPS View 闪烁和卡住

css - 文本对齐无法以特定方式工作

javascript - 从 Accordion 弹出中删除奇怪的故障

php - PHPMailer 和 Gmail &lt;style&gt; 的问题。不确定 Gmail 是否仍在处理它

html - 如何让一个声音文件在整个网站持续播放?