Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

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: ,
Posted on Friday, November 13, 2009 6:21 AM | Back to top


Comments on this post: Apply CSS to all Textboxes

# re: Apply CSS to all Textboxes
Requesting Gravatar...
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.
Left by biswanath on Nov 13, 2009 7:05 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
"to be more specifig

input[type="text"]"

Yep you are correct, I updated the post.
Left by Bunch on Nov 16, 2009 6:49 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Your information is so useful for me, to applu specific css to textbox..

thanx buddy
Left by Rubydeveloper on Mar 05, 2010 2:13 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
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...
Left by Rubydeveloper on Mar 05, 2010 2:15 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Very Good Post
Left by Guess on Aug 18, 2010 4:50 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Thanks!
So usefull tips about Css to All text boxes and buttons
but tell me that is this css have browser-compatabiliy?
Left by wazir khan on Oct 18, 2010 2:49 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
This didn't work in Visual Studio IDE
Left by Rob on Oct 25, 2010 5:53 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Thanks a lot.
This helped me to design my form eligantly.
Left by komal on Oct 09, 2011 9:11 AM

# re: Apply CSS to all labels
Requesting Gravatar...
please tell me how to apply css to labels
Left by vishal on Feb 14, 2012 2:15 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
I want to apply a css class to all text boxes which are in readonly mode, without assignin to each control it has to apply for all. How to do?
Left by Rajagopal on Jun 12, 2012 5:15 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Good one! Thnx for the same!
Left by somu on Nov 27, 2012 9:02 AM

# Thanks for the use full post
Requesting Gravatar...
ok.
Left by naveen on Jan 16, 2013 1:24 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
Thanks helped me lotzz
Left by jithin on Feb 16, 2013 1:26 AM

# re: Apply CSS to all Textboxes
Requesting Gravatar...
I have multiple input[type="text"] pieces on my site, however i need to style one of those (the date) slightly differently, how would i call this element in my css file ??
Left by Mat on Mar 03, 2013 2:28 PM

Your comment:
 (will show your gravatar)


Copyright © Bunch | Powered by: GeeksWithBlogs.net