By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,781 Members | 1,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,781 IT Pros & Developers. It's quick & easy.

Attaching CSS classes to web controls

P: n/a
wh
This is more a question of style really, nothing too technical - honest.

My question is what is the preferred way of defining the styles of elements
in an asp.net page?

Supposing I have several *Web* controls (i.e. <asp:label> elements) that I
want to apply a formatting style to. The first method would be to select all
controls in page design view then set the appearance properties in the
properties window. The other method would be to set the CssClass property of
each control then create a new css class in a stylesheet and attach this to
the page.

Personally, I tend to stick with the second method though I was wondering
how much we should know about the underlying html that is generated.
Supposing I have an <asp:label> element. This is rendered as a <SPAN>
element, so in my stylesheet I have the following rule:

SPAN.MyLabel
{
/* define style here */
}

May we always assume that <asp:label> elements get rendered as <span>
elements. I know an alternative would be to not supply the SPAN element
declaration in the css rule and just have:

.MyLabel
{
}

but I prefer to supply as much information as possible to the browser that
reads the stylesheet.

Wayne.
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I think it should be evident that a label will always be rendered
as a span element as a label is not a container nor a collection
of objects.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



"wh" <wa***@no-spam.pyesmeadow.com> wrote in message
news:mnVBc.1379$I43.828@newsfe6-win...
This is more a question of style really, nothing too technical - honest.

My question is what is the preferred way of defining the styles of elements
in an asp.net page?

Supposing I have several *Web* controls (i.e. <asp:label> elements) that I
want to apply a formatting style to. The first method would be to select all
controls in page design view then set the appearance properties in the
properties window. The other method would be to set the CssClass property of
each control then create a new css class in a stylesheet and attach this to
the page.

Personally, I tend to stick with the second method though I was wondering
how much we should know about the underlying html that is generated.
Supposing I have an <asp:label> element. This is rendered as a <SPAN>
element, so in my stylesheet I have the following rule:

SPAN.MyLabel
{
/* define style here */
}

May we always assume that <asp:label> elements get rendered as <span>
elements. I know an alternative would be to not supply the SPAN element
declaration in the css rule and just have:

.MyLabel
{
}

but I prefer to supply as much information as possible to the browser that
reads the stylesheet.

Wayne.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.