I am setting 2 css class in the code behind in ASP.NET
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 ?
To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element. Naming rules: Must begin with a letter A-Z or a-z.
If you want to add attributes, including the class, you need to set runat="server" on the tag. Thanks, I was sure it would be this simple. @Tyler, no. This adds a new class name to the control.
An element is usually only assigned one class. The corresponding CSS for that particular class defines the appearance properties for that class. However, we can also assign multiple classes to the same element in CSS.
HTML elements can be assigned multiple classes by listing the classes in the class attribute, with a blank space to separate them.
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.
txtBox.Attributes.Add("class", "myClass1 myClass2");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With