Solved

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

Posted on 2011-09-20
8
770 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 35
.php tree directory? 5 57
Resolve Dependency Issues 4 47
How to hyperlink e.Rows.Cells[1].Text before it is displayed in the GridView control. 6 17
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

861 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

22 Experts available now in Live!

Get 1:1 Help Now