Apply Style to Every Control on Website in ASP.NET

Introduction

I guess you are expert in styling controls using CSS. But the thing I am going to talk in this post is bit different. Let's look at following asks:

  1. How to apply style to all Label controls on website?
  2. How to apply TextBox background color or font color (ForeColor) to all controls on websites?
  3. How to apply style to all Hyperlink controls on website?

To answer these all question let's read this.

Follow the steps:-

Step 1 : Create a style sheet page by name 'SiteStyle.css' and save this under project root.

Step 2 :
Type following style information in SiteStyle.css page:

    span:hover
    {
        font-size:12px;
        font-style:oblique;
    }
    input
    {
        background-color:#999999;
        color:Blue;
    }
    a:hover
    {
        color:Green;
    }

Please note: I am using span, input and a. span is HTML markup of Label control in ASP.NET and input is HTML markup of TextBox and a is HTML markup of Hyperlink.

Step 3 : Place the reference of the style sheet file in head section of web pages where you wish to apply this style. If you are using master page then it's pretty easy just place only there in the head section. Here is the code that you need to place.

<link href="SiteStyle.css" rel="stylesheet" type="text/css" />

Step 4 : Now all we set to test, let's create any hyperlink or textbox or label on web page see it in action.

I will recommend you to download the sample project attached here to test. I hope you like it. Thanks.