Creative Jar Blog RSS Feed

Input backgrounds scrolling in IE

October 13, 2008 16:32 by Ben

It is assumed that when we apply a background image to an input field that it is fixed. This is the case when short amounts of text is inputed, but once you type more than the length of the field in Internet Explorer, the background starts to move along with the text. Unfortunately, a simple background-attachment: fixed does not fix this problem.

Here is an example of what happens:

 

A work around which I stumbled upon is to wrap the input field in a DIV and apply the background to this, whilst making the input field’s background transparent. Your code should look like this:

#input_wrapper {
    width: 180px;
    height: 26px;
    background: url('input_bg.png') no-repeat top left;
}

input.search {
    width: 156px;
    height: 16px;
    background: transparent;
    border: 0;
    padding: 5px 12px;
    margin: 0;
}

This is tested in Internet Explorer 6+ and Firefox.


Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

June 29. 2009 22:12

you may use this so background will not be scrolled as you type much

#input_wrapper {
width: 180px;
height: 26px;
background: url('input_bg.png') no-repeat top right;
}

PSD-Coder

October 3. 2009 07:35

@PSD-Coder

Thanks for the code

games

Calendar

March 2010
SuMoTuWeThFrSa
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910