Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CSS in ASP.net

0.00/5 (No votes)
16 Feb 2009 1  
Cascading Style SheetsAuthor: Prakash Singh MehraIntroduction: CSS is a cross platform solution for the standardization of website formatting and

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Cascading Style Sheets

Author: Prakash Singh Mehra

Introduction: CSS is a cross platform solution for the standardization of website formatting and provides consistent visual appearance throughout the application.  It works with the conjunction of HTML 4 and so supported by all modern browsers.

Creating Style sheets: To include the empty stylesheet follow:
Website - Add New Item, Select StyleSheet, and click OK.
It will create a css class with mentioned name and .css extension.

Rules: Style sheets consist of rules which define the formatting information for the particular ingredients under the web page. Each rule name has two parts. The portion before the period indicates the tag to which the rule applies. The portion after the period is a unique name (called the CSS class name). Rules can be specified in following manner:
1. If standard tag name (body, h1, td etc) is specified without any period then the rules are applied to all such tags under the web page.
H1
{
font – weight : bold;
}
Constraint will be set to all H1 tag.

2. If only css class name is mentioned (portion after the period) then the rules are applicable to all the tags with specified class name.
.BoldText
{
 font – weight : bold;
}

Constraint will be set to all tags where css class name is specified as “BoldText”.

3. If complete rule name is mentioned (portion at the both side of period) then the rules are applied to the specified tag with the specified class name.
H1.BoldText
{
 font – weight : bold;
}
Constraint will be set to all H1 tags where css class name is specified as “BoldText”.

Applying stylesheet into the web page: Add the <link > tag under the <Head> section and give reference of the specific stylesheet.
<link href="StyleSheet.css"  rel="stylesheet" type="text/css" />
Where href attribute is set to the location of the required stylesheet class (.css).

Now the rules, under the stylesheet, can be applied to the web controls by setting CssClass property:
<asp:Label ID="Label1" runat="server" Text="Hello" CssClass=" BoldText "></asp:Label>

As “BoldText” rule is open for all tags with specified css class name.

 

 

CSS for asp.net server controls: http://msdn.microsoft.com/en-us/library/h4kete56.aspx

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here