IE input background image issue

IE strikes AGAIN!

Just when I thought I was 100% done with the revamp of New Millennium, I noticed an UI issue in IE. I’m surprised I didn’t notice this before. It shouldn’t be anything new. I did some google research but didn’t find anyone mentioning it either.

Applying background image to input tags should be nothing new. You see the little search icons for search inputs all over the web now but did anyone notice in IE if you have a background image set to no-repeat and someone puts some very LONG text in the input field, the background image SCROLLS with the text? This causes very odd behavior.

Here’s my input background-image. I pick this one so I can do background image affect on hover by manipulating background-position.
background image
CSS:
input.formInput { width: 255px; background: #a99787 url(formInput.gif) left top no-repeat; border: 0; padding: 3px; height: 22px; color: #302721; } input.formInput:hover, input.formInput:focus { background-position: -261px top; }

In Firefox, it looks great but in IE if you start putting very looooooooooooooooong text in the input, it will look like crap.
background image looks like crap in IE

Try it out yourself

So does anyone have a good solution for this issue?

If I were to do it, I’d wrap the input in a container and put the background image on the container and hopefully by applying the hover affect on the container, it would get the desirable effect. Of course I will need to test out my theory. But it’s past midnight so I should get some sleep for now.

AND it does work. check it out.

Man, I just love IE.


15 Comments Leave a Comment

maghiel [ Quote ]

i fixed this issue by setting background-attachment to fixed for IE6 and IE7.

March 4th, 2008 at 9:42 am
dodo [ Quote ]

maghiel on 3/4/2008 at 9:42 am said:

i fixed this issue by setting background-attachment to fixed for IE6 and IE7.

Show me an example. I tried that but it didn’t work.

March 4th, 2008 at 9:47 am
maghiel [ Quote ]

dodo on 3/4/2008 at 9:47 am said:

Show me an example. I tried that but it didn’t work.

yes, here

needs some tuning, but it was just a quick test

March 4th, 2008 at 9:57 am
dodo [ Quote ]

maghiel on 3/4/2008 at 9:57 am said:

yes, here

needs some tuning, but it was just a quick test

You seriously tested that in IE?? I tried it in IE 7, it looks weird.

March 5th, 2008 at 6:29 pm
dodo [ Quote ]

also, is
_background-attachment : fixed;
valid CSS? would that validate against W3C?

March 5th, 2008 at 6:31 pm
Dave [ Quote ]

Thanks for this. saved me a lot of time.

July 16th, 2008 at 1:22 pm
nick [ Quote ]

background-attachment:fixed; seems to work in IE6

October 12th, 2008 at 6:47 pm
rr [ Quote ]

if background-attachment:fixed worked in ie7, it’s because it is in quirksmode, not XHTML strict. only xhtml-compliant solution is to wrap the input field in a span or div and apply the bg image to that.

November 1st, 2008 at 12:23 pm
Dennis [ Quote ]

try to set background position to “bottom right”, then it shouldn’t scroll on text overflow

December 1st, 2008 at 5:31 pm
WiReDbeatBoX [ Quote ]

Dennis on 12/1/2008 at 5:31 pm said:

try to set background position to “bottom right”, then it shouldn’t scroll on text overflow

This is the solution right here, very simple, thanks Dennis.

February 18th, 2009 at 1:28 pm
Daniel Nordstrom [ Quote ]

Awesome, saved me some time. :)

Thanks! :headphones:

March 17th, 2009 at 12:24 pm
Janis [ Quote ]

OK, so someone else has encountered this! I wander what is the explanation for IE to do this…

March 23rd, 2009 at 8:45 pm
tom [ Quote ]

The aspect of positioning the background element to the bottom right did the trick for me.

background:#fff url(../Images/input285×28.gif) no-repeat bottom right

However, if you apply padding to the element

padding:6px 10px; background:#fff url(../Images/input285×28.gif) no-repeat bottom right

the text, as it it is typeed, will make the backgroud jump into and out of position. Applying even padding on the both the left and right side of the element will fix this issue.

Tom
Developer

April 9th, 2009 at 7:59 am
Rachel [ Quote ]

Great script, but what about for text areas?

April 30th, 2009 at 9:30 pm
Noah [ Quote ]

tom on 4/9/2009 at 7:59 am said:

The aspect of positioning the background element to the bottom right did the trick for me.

background:#fff url(../Images/input285×28.gif) no-repeat bottom right

However, if you apply padding to the element

padding:6px 10px; background:#fff url(../Images/input285×28.gif) no-repeat bottom right

the text, as it it is typeed, will make the backgroud jump into and out of position. Applying even padding on the both the left and right side of the element will fix this issue.

Tom
Developer

the bottom-right trick works fine, but putting equal padding on both right and left sides of the input box still breaks in IE for me.

October 14th, 2009 at 2:02 pm

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: