1

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!!

12
  • use input.textbox or input[type="text"] Commented Jun 13, 2013 at 7:24
  • I am adding css to: Documentation.css. Commented Jun 13, 2013 at 7:24
  • Also not to forget to mentione, I am using dotnetnuke... Commented Jun 13, 2013 at 7:24
  • try to change the class name Commented Jun 13, 2013 at 7:25
  • @Anna.P, i used that code... didn't work either :( Commented Jun 13, 2013 at 7:25

4 Answers 4

6

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;
}
Sign up to request clarification or add additional context in comments.

Comments

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

Please use input.textbox instead pf only .textbox.

1 Comment

0

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.

Comments

-1

try to add important

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

1 Comment

No, never use !important.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.