Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you apply styles to a label?

Status
Not open for further replies.

qwert231

Programmer
Sep 4, 2001
756
US
I wanted to create some labels with a specific style set up in my .css file. I created a class (
Code:
.nDate
) with specific font and color settings, but when I add
Code:
class='nDate'
to my label code nothing changes. Can I do this?
 
You can yes. I just used a slightly different approach. Instead of declaring a class I used a specific ID. I was using labels for error messages and set the ID to Error for the label in my CSS I then gave the following.

#Error
{
font-size: 12pt;
color: red;
background-color: aqua;
}


HTH That'l do donkey, that'l do
[bravo] Mark
 
Hmmm, very good... can you have multiple Labels with the same ID? (I'll be trying in a bit, but for the sake of anybody else watching...)
 
Yup no problems there. I did this all programmatically.

dim myError as new Label
myError.text = "msg"
myError.ID = "Error"
panelmsgs is a panel already on the form.
PanelMsgs.Controls.Add(myError)
MyError = Nothing


HTML doesn't care if there are multiple ID's VS might I am not sure.

That'l do donkey, that'l do
[bravo] Mark
 
Using the Matrix myself, tho I have VB for VS. (At least not VD)

Anyways, wondering why you do it that way? Do I need to? I just put in the tag...
Code:
<asp:label id=&quot;labelName&quot;>This is my text</ asp:label>
 
I do it that way cause I need the label to only appear under certain cercumstances.

I am sure a class would work just as well if you have problems with the first one.

just use this as an example label

<asp:Label id=&quot;label1&quot; runat=&quot;server&quot; CssClass=&quot;Error&quot;>Label</asp:Label>


and this in your CSS

.Error
{
font-size: 12pt;
color: red;
background-color: aqua;
}

Hope I have helped That'l do donkey, that'l do
[bravo] Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top