Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-20
8
Medium Priority
?
880 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 61

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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…
Suggested Courses

972 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