Learn How to Create Features in Cascading Style Sheets (CSS) in ASP.NET 3.5 C#


This tutorial will introduce cascading style sheets (CSS) features in ASP.NET 3.5. It will illustrate the basic techniques of creating a new Web page and new style sheet.

In this tutorial you will demonstrate how to create a file system Web site, customize it by using the CSS features by creating a three-column page layout using CSS. You will need Visual Studio 2008 or Visual Web Developer 2008 Express Edition and the 3.5 version of .NET Framework.

To start we need to create a new file system Web site by clicking > File > New Web Site. Under the Visual Studio installed templates, click > ASP.NET Web Site. Choose the proper location and name it CSSWebSite.aspx.

We chose Server Intellect for its dedicated servers, for our web hosting. They have managed to handle virtually everything for us, from start to finish. And their customer service is stellar.

Now we are going to add page and style elements. In order to enable you to focus on the formatting and styling tools instead of creating elements to style, a set of page elements are given in this tutorial for you to copy and paste in-between the

tags that include a banner, left and right sidebar sections, a main content section and a footer. These contain text that you can work with and element IDs.

In order to add elements to your page open the default.aspx page. Switch to Source view. Add this code after the


Heading Three

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

This tutorial will show you how to style your web page using Cascading Style Sheets.

This tutorial will show you how to style your web page using Cascading Style Sheets


Save the page. Switch to design View to format the page as you would like.

When using the Design View, you can easily apply styles to page elements and see the results immediately. This way you do not have to write the CSS code and then switch to the page to see whether the styling is actually what you wanted or not. By using the Design View, you can apply styles to page elements on a page in different ways:

You can use inline styles – which are written as the style attribute of an element. These style rules can only apply to that element.

You can write style rules in a style element in the HTML head element of the page – then these can be applied to elements in a current page.

You can write style rules to an external CSS file – then the style rules can be applied to any page of the Web site you want.

We moved our Web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

For this demonstration we will write the formatting and styling information to the page’s style element section and as inline styles. Afterwards you can move the CSS information to an external style sheet to use other features with in Visual Studio 2008.

To format a page banner, switch to Design View and click > Heading text “This is a CSS Styling Page”. You can notice that the Heading is formatted in the H1 element by the box being blue around the text. Next, above the Design View of the Web page, there is a Style Application Toolbar, where the Target Rule list resides. Click > Apply New Style.

Then the New Style Box appears:

The direct Style Application option defaults to manual, so you will have to style manually. In the selector list, click H1 so that you can create a style that applies to all H1 elements. Notice that the Define in list is set to current page. This means that the style rule is created in a style element in the current page. In the font-family select a font such as Comic Sans Serif. Then adjust the font size to xx-large, and in the font-variant box select small-caps, then click > Ok.

To see the code for the changes you just made, switch to Source View and scroll to the style element located inside the head element.

In Visual Studio 2008, there are many different ways to select elements on the page. One way is while in Design View you could use the quick tag selector located at the bottom toolbar.

You can also use the ESC key to go up the Hierarchy of elements.

In order to size the banner switch to Design View, and click > the Text at the top of the page “This is a CSS Styling Page”, then press the ESC key two times and that selects the enclosing element, which in this case is the banner div element.

To glance at the style rule that was just created, go to Split View and scroll to the style element.

Now in the Format menu, click > Background Color. The color picker is displayed > select a color for the banner and click > Ok. You can also apply these style rules that center the text in the headings by setting padding values.

Yes, it is possible to find a good web host. Sometimes it takes a while. After trying several, we went with Server Intellect and have been very happy. They are the most professional, customer service friendly and technically knowledgeable host we've found so far.

In order to position the heading elements inside the banner switch to Design View, and select the banner

element. On the Format menu, click Paragraph. Your screen should look like this:

In the Paragraph box, in the alignment drop-down list, select Center and click OK.

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!

100% SPAM FREE! We will never sell or rent your email address!