Css attribute selector for input type=“button” not working on IE7

前端 未结 8 1253
执笔经年
执笔经年 2020-12-05 20:38

I am working on a big form and it contains a lot of buttons all over the form, therefore I am trying to get working input[type=\"button\"] in my main css file so it would ca

相关标签:
8条回答
  • 2020-12-05 20:58
    input[type="button"]{ text-align:center; }
    

    What do you expect that to do? The text in an <input type="button"> is already centered by default.

    If you want to align the button itself within the parent, you have to set text-align on the parent element, not the button.

    Attribute selectors — with or without quotes — do work on IE7. It's IE6 that's the problem browser there.

    0 讨论(0)
  • 2020-12-05 21:06

    Attribute selectors are, unfortunately, not yet well implemented in all major browsers, because it is CSS3 and not 2.1, the current standard. Because the guys over at W3C are not that quick in making decisions, you better not set your hopes too high, because we won't be able to use css3 any time soon. Some aspects of it are already implemented, but this one isn't (surely not in IE6).

    So, as you already said yourself, it would be much better to provide all of your inputs with a class, and make it a habit to do so every time you create a form. It's always handy and not a lot of work when you are already programming the form.

    When I create a form, I always add the type of an input as a class, e.g.:

    Especially the last two will come in handy in a lot of cases, because you don't háve to style the .button and .submit separately, but you cóuld if you would like to do so.

    0 讨论(0)
  • 2020-12-05 21:10

    They work for me in IE7 (both forms, with and without quotes).

    Maybe there's another selector that is masking yours. You could try making your selector more specific in order to give it more priority, e.g.:

    body form input[type="button"] {
    background: red;
    }
    
    0 讨论(0)
  • 2020-12-05 21:19

    This question is old but if someone have a related problem.. I spend a few minutes trying to solve a similiar problem

    input[type="Submit"] doesn't work on IE7 (despite of IE assigning the style correctly to the input as I saw in dev tools).

    SOLUTION: I switched from Submit to submit and it worked!

    I posted this here because it may help someone when debugging.

    0 讨论(0)
  • 2020-12-05 21:20

    I was struggling getting input[type=button] selectors working in IE7 or IE8. The problem turned out to be that the HTML Pages were missing a "!DOCTYPE" declaration. Once I added

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    

    Then everything worked fine. You can obviously use a different "!DOCTYPE" declaration to suit your requirements.

    0 讨论(0)
  • 2020-12-05 21:20

    For whatever reason, there are times when attribute selectors will not apply before the page is displayed in IE7. This actually just happened to me. My selector was table[bgColor="#c0c0c0"] and would not apply on page load. Since I was using IE9 (Browser Mode: IE7, Document Mode: IE7 Standards), I was able to use F12 Developer Tools to look at my CSS file. I unchecked the selector and then checked it again. The attributes applied after that. This is reproducible exactly in good ol' IE7, so I'm going to have to find a work-around. (Note: Neither using single, double, or no quotes nor making variations in capitalization make an impact here.)

    0 讨论(0)
提交回复
热议问题