如何在 IE6 CSS 中设置 <input type="text"> 的样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/519945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:17:29  来源:igfitidea点击:

How to style <input type="text"> in IE6 CSS?

cssinternet-explorer-6css-selectors

提问by Vilx-

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.

有没有什么优雅的方式<input type="text">在IE6下对所有元素应用某种风格?我可以用一些 JavaScript 来做到这一点,但我想知道是否有更优雅的方法来做到这一点。

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

注意 - 我无法手动将某个类应用于所有文本框。我想避免使用 CSS 表达式

采纳答案by David Hanak

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

AFAIK,IE6 不支持属性选择器,所以我认为答案是否定的。您必须使用以下方法之一:

  1. Add a common class attribute to all <input type="text"/>elements.
  2. Use JavaScript, as you suggested.
  1. 为所有<input type="text"/>元素添加一个公共类属性。
  2. 按照您的建议使用 JavaScript。

Both of which you want to avoid. Too bad.

你想避免这两种情况。太糟糕了。

回答by Jeremy Ricketts

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

如果您碰巧使用 jQuery,请尝试将其添加到您的 onDOMready:

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

Then in your CSS you could so something like:

然后在你的 CSS 中,你可以这样:

input.typeText, input[type="text"] {
     color:#efefef;
}

回答by Rhodri Davies

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

在您的输入元素上放置类属性对您有用吗?

input.text{

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

}

输入文本{

//这里有一些CSS属性和值....

}

  • maybe more elegant than JS
  • 可能比 JS 更优雅

回答by Stuart

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:

您是否还有其他想要与“文本”元素不同的输入元素?如果没有,只需将样式应用于所有带有 CSS 的输入元素:

input {
border: 1px #8194b2 solid;
font : normal 100% "Tahoma", sans-serif;
}