How to assign CSS element to ASP.NET namespace

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
 
E

Eliyahu Goldin

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
 
L

Leor Amikam

OK, thanks.

I guess I could also maybe on page_load time set the style in code.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top