user2478115
user2478115

Reputation: 141

Why can't I apply css on textboxes in asp.net?

I have a problem with applying css on textboxes in asp.net!!

Here is my textbox:

<asp:TextBox ID="TextBox1" CssClass="textbox" runat="server" Height="22px" Width="128px" 
    BackColor="#CCCCCC"></asp:TextBox>

As u see I added CssClass to the textbox. Here is the css i am using

.textbox
{ 
   background-color: Red;
   font-weight: bold;
}

What is the problem? I googled, but can't find the answer!!

Upvotes: 1

Views: 9619

Answers (4)

Deepak Saralaya
Deepak Saralaya

Reputation: 457

try to add important

input[type=”text”]
 { 
 background-color: Red!important;
 font-weight: bold;
}

Upvotes: -1

Mahmood Dehghan
Mahmood Dehghan

Reputation: 8265

It's a css style rule precedence problem. BackColor property that you have specified translates to style="background-color:#cccccc". so this color is applied instead of red (css class). and also DonNetNuke css rules may override your rules.

So, use more specific rules (like the one @Gayatri mentioned in his answer). Use browsers 'Inspect element' future to determine witch style is overriding others.

Upvotes: 0

nunespascal
nunespascal

Reputation: 17724

Remove your BackColor="#CCCCCC" attribute. Asp.net renders this as in inline css style on the element.

Inline styles have more precedence in CSS over css classes.

<asp:TextBox ID="TextBox1" CssClass="textbox" runat="server" 
     Height="22px" Width="128px"></asp:TextBox>

.textbox
{ 
   background-color: Red;
   font-weight: bold;
}

Upvotes: 6

Gayatri
Gayatri

Reputation: 554

input.textbox
{ 
 background-color: Red;
 font-weight: bold;
}

Please use input.textbox instead pf only .textbox.

Upvotes: 1

Related Questions