Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
205 views
in Technique[技术] by (71.8m points)

css - Issue with Input & Select tag height in form

I am making a form. When I give the same height and width to <input> and <select> tags, the <select> tag is not taking the same height as the <input>.

There seems to be one pixel difference in height.
What's the problem?

input {
  width: 100px;
  height: 20px;
  vertical-align: top;
}

select {
  border: 1px solid #ccc;
  vertical-align: top;
}

option {
  color: red;
  width: 100px;
  height: 20px;
  text-decoration: underline;
}
<input type="text">
<select>
  <option>first option</option>
  <option>second option</option>
</select>
question from:https://stackoverflow.com/questions/9767612/issue-with-input-select-tag-height-in-form

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have to give height to your select & give box-sizing property for this also.

select {
    border:1px solid #ccc;
    vertical-align:top;
    height:20px;
}
input, select{
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}

Check this http://jsfiddle.net/RCnQa/16/

Works on IE8 & above.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...