19

I have a problem getting the text in an input to show correct in Internet Explorer 8. Firefox, Safari and Chrome all show the same.

Firefox, Safari and Chrome

Firefox, Safari and Chrome

Internet Explorer 8

Internet Explorer 8

    <form action="" method="get">
       <input id="q" name="q" type="text">
       <input id="s" name="s" type="submit" value="Sök">
    </form>

#q {
    background:url(../../image_layout/search_field.png) no-repeat;
    width:209px;
    height:32px;
    padding:0 5px 0 5px;
    text-align:left;
    margin:0;
    border:0;
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;
    font-weight:bold;
    color:#09305b;
    font-weight:bold;
    position:absolute;
    left: 0px;
    top: 19px;
}
#s {
    background:url(../../image_layout/serach_buttom.png) no-repeat;
    width:56px;
    height:34px;
    padding:0;
    margin:0;
    color:#FFFFFF;
    font-family:Arial, Helvetica, sans-serif;
    font-size:14px;
    font-weight:bold;
    border:0;
    position:absolute;
    left: 225px;
    top: 17px;
}
lejahmie
  • 17,938
  • 16
  • 54
  • 77
  • 1
    IE... Such a depressing piece of software :-( I feel your pain! One thing to try (if you haven't got it already) is to set the doctype to strict - I spent about 2 days making a site work in IE, and later realizing I'd accidentally used the Transitional doctype :-P Oh the pain. – Bojangles Mar 10 '11 at 11:10

9 Answers9

23

Try specifying a line-height: 34px or thereabouts.

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
  • Ah, the good old line-height how could I forget :) Funny that it doesn't seem to affect Firefox at all, where it already looks good. But it does the work for IE. – lejahmie Mar 10 '11 at 11:46
  • 2
    I tried this and it worked with placing the text correctly. However, in other, modern browsers the caret are now as tall as the input field, and it looks unnice.. Anyway to fix that? – stinaq Aug 07 '13 at 07:43
  • @squ did you ever get a solution to the huge caret? I have the same issue – tmsimont Oct 11 '13 at 16:17
  • @tmsimont Not really, I had to do an IE specific hack and set line height for only IE and do the regular height for the other browsers.. – stinaq Oct 14 '13 at 07:57
  • Worth having a look at answer below: http://stackoverflow.com/a/14876642/731782 solved it for me. – DavidP Sep 01 '14 at 19:23
11

There is a CSS3 rule: the box-sizing. This rule is supported by IE8.

The IEs(including IE8) have non-standard box model, where padding and border are included into width and height whereas other browsers go with standard and don't include padding and border into width . It is described in detail here.
By setting the box-sizing to content-box you tell the browsers not to include border and padding into width, and if you set box-sizing: border-box, all browsers will include border and padding into width. This or this, the display will be consistent across all modern browsers(not that IE8 is so modern, but it supports this rule too :).

Shimon Rachlenko
  • 5,469
  • 40
  • 51
5

I had to set the line-height and display: inline. No idea why, but it worked for me.

bergie3000
  • 1,091
  • 1
  • 13
  • 21
2

Try setting a line-height targeting IE8 and below, like this:

line-height: 32px\9;

line-height value should be equal to input's height and \9 will target IE8 and below.

Paul E. Stanciu
  • 133
  • 2
  • 6
2

Set a line-height property for search input field #q?

Munim
  • 6,310
  • 2
  • 35
  • 44
1

The position of input should be position:absolute; in order for line-height:37px; and display:inline; to work.

CL.
  • 173,858
  • 17
  • 217
  • 259
keen
  • 11
  • 1
0

I had much trouble with that, and finally i resolved it:

for ex. you set

  INPUT {
   line-height: 44px
}

and...

  INPUT:focus {
    line-height: 45px
 }

this one...f... pixel makes the difference (focus shoud have +1px more than normal) and now you have your cursor in good position at IE8.

Roopendra
  • 7,674
  • 16
  • 65
  • 92
sinner
  • 1
0

Just use

line-height: 34px!important;
height: 34px;
varkadov
  • 1
  • 1
0

I can't comment yet, Matthew's answer worked for me, but in case people wanted an IE-only wrapper without searching anywhere else:

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    line-height: 20px;
}
suzumakes
  • 760
  • 3
  • 12