简体   繁体   English

选择相同宽度的选项

[英]Select option same width

http://jsfiddle.net/73vbu0kg/ http://jsfiddle.net/73vbu0kg/

select {
  -moz-appearance: none;
  border: 1px solid #333;
  color: #999;
  display: inline-block;
  font-size: 12px;
  height: 39px;
  padding: 0 15px;
  vertical-align: top;
  width: 218px;
}
select option {
  padding: 7px 15px;
}

Why option field is wider than select? 为什么选项字段比选择字段宽? How do you fit it to same width both select and option with same text padding? 如何用相同的文本填充将select和option设置为相同的宽度?

change your style as below 改变你的风格如下

select option {
  padding: 7px 4px;
}

The reason you have hidden overflow on the text id because in your CSS you are giving the select a fixed width . 您在文本ID上隐藏溢出的原因是因为在CSSselect了固定width If you remove the width it will expand to the width it needs to display all of the option values. 如果删除宽度,它将扩展到需要显示所有option值的宽度。 If you don't want the select bigger then that leaves you with changing the font-size 如果您不希望选择的font-size更大,则需要更改font-size

 select { -moz-appearance: none; border: 1px solid #333; color: #999; display: inline-block; font-size: 12px; height: 39px; padding: 0 15px; vertical-align: top; } select option { padding: 7px 15px; } 
 <select> <option selected="selected" value="">Please select one:</option> <option value="1">Prayer Requests</option> <option value="2">Financial Assistance</option> <option value="3">Life, Illness & Loss</option> <option value="4">Marriage, Relationship & Family</option> <option value="5">Life Controlling Issues & Addictions</option> <option value="6">Counseling & Life Improvement</option> <option value="7">Other</option> </select> 

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

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