How do I style controls using CSS ?


I have a fairly descent understanding of both CSS and, but not sure how to put them together.   For example, how can I apply CSS button styling to a ASP control button?  Thanks for any help.
LVL 10
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

just defining class
ASP.NET controls are just rendered as standard html elements so any stylesheet rules you define for those elements will apply to the corresponding controls too (eg. asp labels are spans, panels are divs, gridviews come out as tables etc etc).
Additionally most controls also have a "cssclass" attribute that you can use to specify a css class for that particular control on the server tag.  eg <asp:button runat="server" ID="button1" cssclass="btnStyle" /> that kind of thing.
Something to watch out for though is that the ID attribute doesn't necessarily come out the same when rendered (if in user controls, templated controls etc) so care needs to be taken when using the #selector in your style sheet.
Here is the sample code:

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <style  type ="text/css" >
   font-family:'trebuchet ms',helvetica,sans-serif;
    <form id="form1" runat="server">
        <asp:Button ID="btnSubmit" runat="server" cssclass="btn" Text="Submit" />


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

P1ST0LPETEAuthor Commented:
So the style sheet needs the "runat="server" attribute as well for it to work correctly?
No, the style sheet interacts with the html elements, not the server ones.
P1ST0LPETEAuthor Commented:
Thanks for the help guys.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.