Solved

How to apply CSS style to ASP.NET label within a panel control

Posted on 2011-09-20
8
754 Views
Last Modified: 2012-05-12
Hi,

I'm trying to apply a style that's defined in an external CSS file to an ASP.NET label control that is within a panel control.  Given the layout of this panel I need to apply the style directly to each control but can't get style to work with the label control.  I've tried various ways including assigning an ID to the control and creating a style for the ID.  I've tried defining the style as a class as well with no success.  The only way I've been able to apply the style is by specifying my container name and then applying the style to the span element eg.

#panel span
{
    margin-left: 10px;
    width: 75px;
}
 but this is not what I want because it applies to all the label controls.  Is what I'm trying to do possible?

Thanks
0
Comment
Question by:obb-taurus
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 16

Expert Comment

by:disrupt
ID: 36570866
0
 

Author Comment

by:obb-taurus
ID: 36570911
I already tried creating a class and applying it to the CSSStyle property of the label with no success.
0
 
LVL 16

Expert Comment

by:disrupt
ID: 36570926
How did you do so? Can you post an example?
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36570951
this is fine for me
<style>
#panel span
{
    margin-left: 100px;
    width: 75px;
    color:red;
}
</style>

<div id=panel>
<span>what is this?</span>
<div>

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:obb-taurus
ID: 36571011
I tried using a class again and this time was able to get it working, the only odd thing is it ignored text align command which is why it looked like the class method wasn't working to begin with so I had to use a span to get the text align to work, not sure why that would be, what I have is as follows:

#panel span
{
  text-align:left;
}

.labelStyle
{
  width: 200px;
}

It would not work properly like this:

.labelStyle
{
  text-align: left;
  width: 200px;
}
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36572659
try using this:
text-align: left !important;
0
 

Author Comment

by:obb-taurus
ID: 36574355
Eyal,

That did the trick although I have never seen that syntax like that before but I do have to admit that I'm not by any stretch very knowledgeable about CSS.  Do you know why the normal form of text-align does not work on an ASP.NET label control?

Thanks
0
 
LVL 15

Accepted Solution

by:
Eyal earned 250 total points
ID: 36578186
it's not related to the ASP.NET label control at all. it's hierarchy of CSS.

you can see in firebug (css tab) exactly what is the reason why this definitions didn't worked (of cores remove the !important statement to see why)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now