Why input[type=text] is not working in IE

2019-05-23 00:11发布

问题:

I have some style like this:

<style type="text/css">
input[type=text]{
width:300px;
}
</style>

the above code works in chrome and firefox. Why not in IE? I am using this code in Reporting services at the end of Reports.aspx file.

回答1:

It works fine in IE8, assuming the page is loading in IE7 or IE8 standards mode (not quirks)

Edit

You've said you're using IE8. In which case, use the developer tools (F12), locate your text box, and check what styles are being applied.

Edit 2

Don't know which version of reporting services you're using. Just went to a 2000 instance, and the report manager is serving up pages that render in quirks mode, so good luck getting much, if any, styling to work.

Edit 3

You may be able to force IE to render in IE8 mode by adding a meta tag to the head within the aspx pages. E.g. :

<head>
<meta http-equiv="X-UA-Compatible" content="IE=100" >
<!-- Rest of <head> -->


回答2:

Which version of IE?

IE6 and lower do not support attribute selectors.

Just use a class, keep it simple:

input.text
{
   width:300px;
}

<input type="text" class="text" />


回答3:

Double check that you don't have a space between the "input" and the "[". This burned me lately. Worked in FF/Chrome but not IE.



回答4:

Use the IE7-JS script. (It was originally created to add some features of IE7 to IE6, thus the name.)

It can add this feature to both IE6 and IE7. (Note that IE9.js is newest and it also fixes a bunch of other things in how IE interprets CSS.)