2

Given the following code:

<form>
  <input type="text">
  <select>
    <option>Foobar</option>
  </select>
</form>

With the following CSS:

input, select {
  width: 200px;
}

Internet Explorer displays the text input slightly larger than the select box. Is there a way (that hopefully doesn't break compatibility with other browsers) to make them exactly the same width?

Thanks,

gnuvince

gnuvince
  • 2,247
  • 19
  • 27

4 Answers4

3

Use a conditional comment:

<style type="text/css">
input, select {
    width: 200px;
}
</style>
<!--[if IE]>
    <style type="text/css">
    select {
        width: 195px; /* Resize down hwever much is needed to make them even. */
    }
    </style>
<![endif]-->

More on Conditional Comments

animuson
  • 52,378
  • 28
  • 138
  • 145
2

How about box-sizing: border-box ?

JunkyXL
  • 21
  • 1
1

You'll have to do this manually when you detect IE

input, select {
  width: 200px;
}

.ie-select {
  width: 220px;
}
Roman
  • 10,126
  • 17
  • 62
  • 99
0
input {
    width: 200px;
}
select { /* for IE */
    width: 206px;
}
html > /**/ body 
select { /* for other browsers */
    width: 204px;
}

Alternatively: CSS: how to set the width of form control so they all have the same width?

Community
  • 1
  • 1
reisio
  • 3,232
  • 1
  • 22
  • 17