How do I style Asp.net controls using CSS ?

Hi,

I have a fairly descent understanding of both CSS and Asp.net, 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
P1ST0LPETEAsked:
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.

Maverick_CoolCommented:
just defining class
0
NazoUKCommented:
ASP.NET controls are just rendered as standard html elements so any stylesheet rules you define for those elements will apply to the corresponding asp.net 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.
0
raja_ind82Commented:
Here is the sample code:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <style  type ="text/css" >
    input.btn{
   color:#050;
   font-family:'trebuchet ms',helvetica,sans-serif;
   font-size:small;
   font-weight:bold;
    background-color:#fed;
    }
   </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="btnSubmit" runat="server" cssclass="btn" Text="Submit" />
      </div>
    </form>
</body>
</html>

Thanks,
M.Raja
0

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?
0
NazoUKCommented:
No, the style sheet interacts with the html elements, not the server ones.
0
P1ST0LPETEAuthor Commented:
Thanks for the help guys.
0
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
ASP.NET

From novice to tech pro — start learning today.