CSS 如何将多个“CssClass”分配给 asp.net 中的控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/497837/
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 can I assign more than one "CssClass" to a control in asp.net
提问by ahmed
Can I assign more than one "CssClass" to a control in asp.net?How to do this?
我可以在 asp.net 中为一个控件分配一个以上的“CssClass”吗?如何做到这一点?
回答by Larsenal
To assign class "myClass1" and "myClass2" you simply say:
要分配类“myClass1”和“myClass2”,您只需说:
<asp:Label runat="server" CssClass="myClass1 myClass2" />
This is the same approach you'd use in normal HTML as in:
这与您在普通 HTML 中使用的方法相同:
<div class="myClass1 myClass2"></div>
回答by Khb
If you wanted to add another class programmatically and don't know what classes have already been added
如果您想以编程方式添加另一个类并且不知道已经添加了哪些类
MyControl.CssClass += " newclass";
回答by Sam
You can try the eqivalent of:
您可以尝试等效于:
class="class1 class2"
班级=“班级1班级2”
So if it's a property just try throwing the classes with a space between them in there.
因此,如果它是一个属性,只需尝试将类与它们之间的空格放在那里。
回答by Matthew Olenik
I imagine it's just like setting the class attribute in an XHTML element.
我想这就像在 XHTML 元素中设置 class 属性一样。
<p class="foo bar"></p>
<asp:Something CssClass="foo bar" runat="server" />