Click here to Skip to main content
15,867,993 members
Articles / Web Development
Article

CSS in ASP.net

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Oct 2013CPOL2 min read 13.3K   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

This article was originally posted at http://wiki.asp.net/page.aspx/657/css-in-aspnet

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

755 members

Comments and Discussions

 
-- There are no messages in this forum --