Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-20
8
Medium Priority
?
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 59

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Suggested Courses

705 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