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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting style for Label element 1

Status
Not open for further replies.

Gill1978

Programmer
Jun 12, 2001
277
GB
Hi All,

I'm trying to add the CssClass property on an <asp:Label> element. However the class that i've set up is not working

The .css file has the following code:
Code:
label.header
{
	background-color : Red;
	font-family : MS Sans Serif;
	font-size : 2px	

}

The html code has the following:

Code:
        <asp:Label
            CssClass="header" 
            ID="Label1" 
            runat="server"
            Text="Test 1">
        </asp:Label>

Can anyone see what i'm doing wrong here???

Thanks in advance,

Julie
 
Not sure about the ASP part, but you probably want to use sans-serif or put quotes around 'MS Sans Serif' so you don't confuse the browser. 'Label' (uppercase) may or may not be the same as 'label' (lowercase).
In addition, 2px for a font-size is going to be illegibly small.

What does the actual html output look like (i.e. view source after asp processes it)?

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
There is no HTML element named label, so assigning style values to it doesn't do anything. If you look at the final HTML output, you should be able to see how to modify you CSS to do what you want.

Lee
 
I thought that was the html in the .aspx file???
Thanks
Julie
 
If it uses runat="server" it's obviously not client-side code, and the browser only sees client-side HTML.

Lee
 
This is what the html output is:
Code:
    <div style="text-align: center">
        <span id="Label1" class="header">Comsys 2</span>
        <br />
        <br />
     </div>
 
Then use
Code:
span.header
instead of
Code:
label.header
or just
Code:
.header

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
.... right let me start again ...

The reason why I have label.header is so that this formatting only relates to the header on the screen not all the other 20 labels on the same screen.

Now I have:

.css file:
Code:
Label.header
{
	background-color : Red;
	font-family : "MS Sans Serif";
	font-size : 2px	

}


aspx file:
Code:
    <div style="text-align: center">
        <asp:Label
            CssClass="header" 
            ID="Label1" 
            runat="server"
            Text="Test 1">
        </asp:Label>
        <br />
        <br />
     </div>

html file:
Code:
    <div style="text-align: center">
        <span id="Label1" class="header">Comsys 2</span>
        <br />
        <br />
     </div>

Why it's turned into a Span I have no idea ...new to WEB ... .NET

Any ideas ...


 
Just do what Cory (cLFlaVA) or I suggested in your css in our posts at 9:57 and 9:58.

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
Gill1978, I was hoping that you'd see things for yourself and come to the conclusion that traingamer provided.

Lee
 
.header worked fine ... the reason why I was bangin on about it was because I kinda like to know why I label.header didn't work (which is why I used this forum)... as that was one of the examples i'd seen while doing this ...

What's with the sarcasm ... it was just a question ....

Thanks fella's ...
 
No sarcasm. If you figure out solutions on your own with some direction, you are better equipped to recognize paths to take in the future to find answers to your problems.

Lee
 
was because I kinda like to know why I label.header didn't work

don't take this the wrong way, but i suggest you read up a little on CSS.

the "label" before the ".header" means, this is the style definition for all HTML label tags that have the class of "header".

you saw that i asked for your actual HTML, not your ASP. you provided the HTML, which showed NO label elements, but rather a SPAN element.

if you were to use "span.header", as traingamer said, this would have worked. similary, the more vague ".header" means ANY HTML ELEMENT with a class of "header" gets this style.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Your both right of course ... sometimes you're dumped with a project you have no idea about because thats the way that work sometimes is ... that's life. Anyhow ... I spent an hour reading up about the class's in css ... which is why I was all confused about why it didn't work ... I'd assumed what worked with html would work with the asp page that had html in it.

I know better now ... Thanks for the explanation ... I know why it didn't work before ... though I guess i'll need to do some asp reading to explain why an <asp:label> tag translates into Span tag in html ... because thats logical?!!?

Thanks again

 
Yes, it's completely logical. It's ASP.NET (.aspx pages) and the server translates it into plain HTML. The runat="server" directive is a clue that the server is supposed to process something and spit out some HTML that's different from the code on the screen, just like running <script runat="server"> does in classic ASP.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top