How to assign CSS element to ASP.NET namespace

  • Thread starter Thread starter Leor Amikam
  • Start date Start date
L

Leor Amikam

I want to use a css element and apply it to all labels on a page with the
"asp:label" tag.

I defined a CSS class:

..cls1
{
font-weight: bold;
color: royalblue;
font-family: Verdana;
}

and then can assign to the control using the CssClass property:

<asp:label id="Label1" style="Z-INDEX: 101; LEFT: 335px; POSITION: absolute;
TOP: 69px" runat="server"
CssClass="cls1" Height="42px" Width="210px">Label</asp:label>

However, this is a pain to have to manually assign to each label control. I
want to define one CSS element that maps to "asp:label"
and have it apply to all label controls w/o having to explicitly assign the
CssClass. Is there a way to do this?

Thanks!
Leor
 
Leor,

An asp:label renders as a <span>. You can try

span
{
font-weight: bold;
color: royalblue;
font-family: Verdana;
}

but you are risking to get some side effects since asp.net uses <span> not
only for labels. I recommend to put up with the pain and keep using
CssClass.

Eliyahu
 
Leor -

Put a link in your html as below (StylesVerdana in this case is the name of
the style sheet - it will be whatever the name of yours is):

<head>
<title>Title</title>
<meta content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
<meta content="Visual Basic .NET 7.1" name=CODE_LANGUAGE>
<meta content=JavaScript name=vs_defaultClientScript>
<meta content=http://schemas.microsoft.com/intellisense/ie5
name=vs_targetSchema>

<LINK href="StylesVerdana.css" type=text/css rel=stylesheet >

</head>

I included all of the other code so you could see where it goes.

This will give the proper font to all labels without having to do them
individually. Keep in mind, though, that you will have to individually
insert any font SIZES that are different than the one in your css style sheet.

HTH
 
Back
Top