CSS 如何在后面的代码中添加两个CSS Class来控制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2955951/
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
How to add two CSS Class to control in the code behind?
提问by Amr Badawy
I am setting 2 css class in the code behind in ASP.NET
我在 ASP.NET 后面的代码中设置了 2 个 css 类
I could either do:
我可以这样做:
txtBox.Attributes.Add("class", "myClass1");
txtBox.Attributes.Add("class", "myClass2");
it's always apply one Class .. How can i add thw two classes ?
它总是应用一个类.. 我怎样才能添加两个类?
回答by Marc
The Add method is actually a Put, since it replaces the value behing the key "class"
. In HTML/css you can have several classes by separating with a space.
Add 方法实际上是一个 Put,因为它替换了 key 后面的值"class"
。在 HTML/css 中,您可以通过用空格分隔来拥有多个类。
txtBox.Attributes.Add("class", "myClass1 myClass2");
回答by Riain McAtamney
try
尝试
txtBox.Attributes.Add("class", "myClass1 myClass2");
I think this will work.
我认为这会奏效。
回答by Linkall Web Tech Pvt. Ltd.
try
尝试
txtBox.Attributes.Add("class", "my_Class1 my_Class2");
回答by Jakaria
You can also try
你也可以试试
txtBox.CssClass = "myClass1 myClass2";
txtBox.CssClass = "myClass1 myClass2";