2

What is the best way to add a cascading stylesheet (CSS) to a web application project in visual studio 2010?

For example if I have the followingL


<asp:Label ID ="lName_lbl" runat="server" text="Last Name:  "></asp:Label>
<asp:TextBox ID="lName" runat="server"></asp:TextBox>
<br />

How do i style all asp labels to have the same properties?

1
  • Let's watch our tag choices a little better, m'kay? visual isn't exactly a very good tag. Commented Dec 19, 2011 at 16:11

3 Answers 3

2

As the other answers have correctly mentioned, you can use the CssClass attribute for controls that support it.

You can also style the elements using CSS Selectors

ASP.Net makes it easy to add stylesheets to your application via the App_Themes folder. CSS specified in here corresponding to the theme you set in the page or web.config will be automatically loaded. No need to link the css manually.

EDIT:

If you don't already have an App_Themes folder, right click your project, and choose Add->Add ASP.Net Folder->Theme and this will create it for you. To make sure the Theme is used set it in the web.config (via the <pages theme="" attribute) or at the page level. See the App_Themes page for more information.

Sign up to request clarification or add additional context in comments.

2 Comments

creating a blank web application does not add an App_Themes folder
You can right click on the web application at the project level, select "Add ASP_Net folder" (or similar), and one of the options will be App_Themes
2

ASP.NET controls have the CssClass property which you can use to style your control. There's also some good advice on using CSS with ASP.NET here.

2 Comments

Ok but how do I include the css into my document? Using the standard <link> tag available in HTML? Is there a better way to do it within vis studio 2010?
Yes, the output is still HTML, so you can use the standard <link> or <style> tag.
1

You can use the CssClass attribute on your labels or you could define a style to apply to all spans since .NET renders <asp:Label /> as a span.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.