Input backgrounds scrolling Problem in IE

Posted: May 13, 2011 in CSS, HTML
Tags: ,

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. So Apply this solution. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s