SIGN UP MEMBER LOGIN:    
ARTICLE

How to use StyleSheets

Posted by Rekha Articles | ASP, JavaScript, CSS December 29, 2009
This article explains how to use style sheets in Web applications.
Reader Level:

How to use StyleSheet:

  • Style sheets describe how documents are presented on screens, in print, or perhaps how they are pronounced.
  • Cascading Style Sheets, or CSS, is the recommended way to control the presentation layer in a web document. The main advantage of CSS over presentational HTML markup is that the styling can be kept entirely separate from the content. For example, it's possible to store all the presentational styles for a 10,000-page web site in a single CSS file. CSS also provides far better control over presentation than do presentational element types in HTML.
Step 1:

Right click on solution explorer - Add New Item - Add StyleSheet.css

Step 2:

In the body class of StyleSheet.css just give the property which has to be set for any page in the project.
 

Source code: StyleSheet.css

body
{

background-color :Silver ;
}

Step 3:

Drag n drop StyleSheet.css from solution explorer

image2.gif

 Step 4:

Write the classes defining the style which has to be applied

Example: textbox background color has to be same in all the pages so we define a class .txtbox with the background color

Source code: StyleSheet.css

body
{

background-color :Silver ;
}
.txtbox
{
widows:20;
height:10;
background-color:Aqua;
}
.Dropdownlist
{
width:auto;
background-color :Lime;
}

Step 5:

Drag a textbox and give txtbox class as cssclass in the property

image3.gif

 
Source code: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>

</
div>
&nbsp;

<
br />
<br />
<asp:TextBox ID="TextBox1" runat="server" CssClass="txtbox"></asp:TextBox>
</form>
</body>
</html>

Step 6:

Add a new form and the same StyleSheet.css can be used for any textbox place in the project

Login to add your contents and source code to this article
share this article :
post comment
 

good job

Posted by rajeev pandey Mar 25, 2012

thanks it was useful

Posted by Divya S Nov 11, 2010

hi mam u done it well.......thank you...

Posted by sabeesh kutty Sep 09, 2010

How to add background image to this ?

Posted by Arnel Rustemovic Aug 28, 2010

thank u very match author

Posted by mahesh kannan Apr 10, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor