Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 77, comments - 89, trackbacks - 0

My Links

News

Tag Cloud

Archives

Green

Apply CSS to all Textboxes

Here is a really quick CSS item to apply styles to different types of textboxes in an ASP.Net application. A plain old vanilla asp:textbox control will show as an Input if you view the source of the page. To set the styles of all those controls from a css file you can add this to your css:

input[type=”text”]
{
    font-size: 8pt;
    font-family: Arial;
}

Then you do not need to add the CssClass property to the textboxes in the aspx file. The input section of the css will be applied automatically. This saves some time and you only need to change the styles in one place. However if you have a textbox with the TextMode property set they will not render as an Input but rather as a Textarea. So to set all those types of asp:textboxes in your css file just add the following to you css file:

textarea
{
    font-size: 8pt;
    font-family: Arial;
}

After that both “types” of textboxes should have the same font size and family.

NOTE: See the first comment. Using input[type=”text”] will work for compliant browsers to prevent the style from being applied to other input types like buttons, checkboxes, radio, etc.

Technorati Tags: ,
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Friday, November 13, 2009 6:21 AM |

Feedback

Gravatar

# re: Apply CSS to all Textboxes

to be more specifig

input[type="text"] {
font-size: 8pt;
font-family: Arial;
}

If not you will be getting all the other inputs, like button with the same style.

Correct me if I am wrong.
11/13/2009 7:05 AM | biswanath
Gravatar

# re: Apply CSS to all Textboxes

"to be more specifig

input[type="text"]"

Yep you are correct, I updated the post.
11/16/2009 6:49 AM | Bunch
Gravatar

# re: Apply CSS to all Textboxes

Your information is so useful for me, to applu specific css to textbox..

thanx buddy
3/5/2010 2:13 AM | Rubydeveloper
Gravatar

# re: Apply CSS to all Textboxes

hey, 1 want to tell you.. i have to apply style to all buttons, but submit is different than button so for multiple types , u can have

input[type="button"],[type="submit"]{
}
enjoy...
3/5/2010 2:15 AM | Rubydeveloper
Gravatar

# re: Apply CSS to all Textboxes

Very Good Post
8/18/2010 4:50 AM | Guess
Gravatar

# re: Apply CSS to all Textboxes

Thanks!
So usefull tips about Css to All text boxes and buttons
but tell me that is this css have browser-compatabiliy?
10/18/2010 2:49 AM | wazir khan
Gravatar

# re: Apply CSS to all Textboxes

This didn't work in Visual Studio IDE
10/25/2010 5:53 AM | Rob
Gravatar

# re: Apply CSS to all Textboxes

Thanks a lot.
This helped me to design my form eligantly.
10/9/2011 9:11 AM | komal
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: