Adding CSS to a C# Web Application

2019-07-18 22:42发布

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?

3条回答
何必那么认真
2楼-- · 2019-07-18 22:53

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-07-18 22:58

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.

查看更多
Rolldiameter
4楼-- · 2019-07-18 23:08

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.

查看更多
登录 后发表回答