views:

126

answers:

4

I know, I know IE6 right? Well no matter how strong the argument -- I have to please IE6 at the moment.

I have a text input field. I was to style it's font and background colors. But I can't get IE6 to display the changes I'm altering. Here;s my markup and css.

<style>
    input[readonly='readonly'], input.readonly {
    color:red !important;
    background:#EBEBE4 !important;
    border:solid 1px #7F9DB9 !important;
    cursor:default;
}
</style>

and here is my form.

<form name="mainform" method="post" action="/link.aspx" id="mainform">
  <div class="section">
      <label for="shipFirstName">First Name:<abbr title="Required field">*</abbr></label>
      <input type="text" name="shipFirstName" id="shipFirstName" value="Rich" readonly='readonly' class='readonly' maxlength="13" />
      <label for="shipFirstName">Last Name:<abbr title="Required field">*</abbr></label>
      <input type="text" name="shipLastName" id="shipLastName" value="Sturim" readonly='readonly' class='readonly' maxlength="26" />
  </div>
</form>

I know the problem lies in the selectors

input[readonly='readonly'], input.readonly

But I'm not sure what I have to do to get IE6 to recognize the "readonly" class.

Any ideas?

+1  A: 

Try using

input[readonly] {
    // stuff
}
Ólafur Waage
A: 

Attribute selectors don't work in IE6. If you use jQuery, however, it abstracts away the notion of attribute selections.

$('input[readonly="readonly"]').addClass('...') would work.

Stefan Kendall
A: 

IE6 doesn't support attribute selectors, I think you just need to get rid of input[readonly='readonly'], this will probably solve your problem.

2 alternative solutions :

  • Add a class attribute to your input (just like you did)
  • Use Javascript.
Soufiane Hassou
+3  A: 

IE6 gets confused by the input[readonly='readonly'] selector and will treat that entire rule as a syntax error. You'll have to create two different rules to make it work:

<style>
    input[readonly='readonly'] {
    color:red !important;
    background:#EBEBE4 !important;
    border:solid 1px #7F9DB9 !important;
    cursor:default;
}
    input.readonly {
    color:red !important;
    background:#EBEBE4 !important;
    border:solid 1px #7F9DB9 !important;
    cursor:default;
}
</style>
Martin
perfect -- thanks Martin!
rsturim
I should mention, the first rule is obviously superfluous in this particular case. I just copied this from a similar situation where the `readonly` class is added with an IE6-specific script, in which case it becomes necessary to duplicate the rule.
Martin