如何在 ASP.NET 中使用 CSS 设置文本框样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1648789/
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 21:12:30  来源:igfitidea点击:

How to style textbox using CSS in ASP.NET

asp.netcss

提问by Vaibhav Jain

I want to add style in ASP.NET textbox control. I couldn't find textbox element in elements list. I can put style in all input controls using the below code in CSS.

我想在 ASP.NET 文本框控件中添加样式。我在元素列表中找不到文本框元素。我可以使用以下 CSS 代码在所有输入控件中添加样式。

input
{
backgroud-color:black;
}

But this changes the background color of all input controls like buttons, radiobox, etc.

但这会更改所有输入控件(如按钮、单选框等)的背景颜色。

I want to do it exclusively with textbox, I don't want to do it with CSS class.

我想专门用文本框来做,我不想用 CSS 类来做。

回答by jerjer

It would be easier to put css class on those textboxes (input type="text")

将 css 类放在这些文本框上会更容易(输入类型 =“文本”)

<style>
   .textbox { /*some style here */ }
</style>

<input type="text" class="textbox" /> or
<asp:TextBox id="someid" runat="server" CssClass="textbox" />

回答by richeym

This will do it:

这将做到:

input[type=text]

Though it might not work in all browsers (e.g. IE). The only way to ensure that would be to add a class or put it inside a span element.

虽然它可能不适用于所有浏览器(例如 IE)。确保这一点的唯一方法是添加一个类或将其放入 span 元素中。

回答by Dan Diplo

A 100% cross browser, that works in IE6, is to make use of asp.net themes and skins. Create a skin filein the app_themes directory and add the following line:

在 IE6 中工作的 100% 跨浏览器是利用asp.net 主题和皮肤。在 app_themes 目录中创建一个皮肤文件并添加以下行:

<asp:TextBox runat="server" CssClass="textbox" />

This will then apply the CSS class "textbox" to everytextbox in your site, assuming you have corresponding CSS and theme references.

假设您有相应的 CSS 和主题引用,这会将 CSS 类“文本框”应用到您站点中的每个文本框。

回答by Nestor

Not 100% sure if this is what you're looking for but you can put CssClass="myTextBoxStyle"in the ASP.NET server-side tag and then define a class called .myTextBoxStylein your stylesheet. It will then only affect textboxes where you've added CssClass="myTextBoxStyle"

不能 100% 确定这是否是您要查找的内容,但您可以放入CssClass="myTextBoxStyle"ASP.NET 服务器端标记,然后定义一个.myTextBoxStyle在样式表中调用的类。然后它只会影响您添加的文本框CssClass="myTextBoxStyle"

回答by rahul

input[type=text]

but won't work in IE.

但不会在 IE 中工作。

Use a class name instead and apply that class to your text elements.

改用类名并将该类应用于您的文本元素。