17

Is there any elegant way of applying a certain style to all <input type="text"> elements under IE6? I can do it with some JavaScript, but I was wondering if there was a more elegant way of doing it.

Note - I cannot apply a certain class to all textboxes by hand. And I'd like to avoid CSS expressions.

Community
  • 1
  • 1
Vilx-
  • 104,512
  • 87
  • 279
  • 422

4 Answers4

14

AFAIK, IE6 does not support attribute selectors, so I think the answer is no. You'd have to use one of the following:

  1. Add a common class attribute to all <input type="text"/> elements.
  2. Use JavaScript, as you suggested.

Both of which you want to avoid. Too bad.

David Hanak
  • 10,754
  • 3
  • 31
  • 39
  • jQuery can make javascript styling a lot less painful as it support selection filters very similar with CSS – Aleris Feb 06 '09 at 11:41
  • 1
    @Alertis: true, but it's still javascript. – David Hanak Feb 06 '09 at 11:43
  • It's an internal use web application which depends heavily on JavaScript anyway. Using it for styling is no problem. I just wondered if there was any better way. – Vilx- Feb 06 '09 at 11:54
  • you can use also IE css expressions, eg: `input { _color: expression(this.type=='text' ? 'red' : 'blue'); }` – S.Serpooshan Dec 26 '16 at 12:11
8

If you happen to be using jQuery, try adding this to your onDOMready:

$('input[type="text"]').addClass('typeText');

Then in your CSS you could so something like:

input.typeText, input[type="text"] {
     color:#efefef;
}
Jeremy Ricketts
  • 2,601
  • 4
  • 29
  • 28
1

Does putting a class attribute on you input element work for you?

input.text{

//some CSS attributes and values here....

}

  • maybe more elegant than JS
1

Do you also have other input elements which you wish to style differently to the "text" element? If not, just apply the style to all input elements with CSS:

input {
border: 1px #8194b2 solid;
font : normal 100% "Tahoma", sans-serif;
}
Stuart
  • 309
  • 1
  • 3
  • 8
  • Unfortunately I indeed wish to leave other types unaffected. I'll be changing things such as height and background-color, so it would reflect pretty nasty on, say, a checkbox. – Vilx- Feb 06 '09 at 11:32
  • Indeed. Since you're only using javascript for some minor styling, I think you can justify using it. It won't affect the functionality for the minority without javascript. – Stuart Feb 06 '09 at 11:35