Solved

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

Posted on 2011-09-20
8
777 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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
 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Input box gone wrong 8 24
How to position loader with CSS 3 39
css selector 1 16
tiny glitch in my main slider 3 23
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

770 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