2

If I am assigning a paricular css class to a control ,it hnherits the class but if i simultaneously give the skin id to the same control then this skin ID overrides the CSS class. Why this is happening?

Now if I am using !important in the css stylesheets then css class property is inherited by the control. .lblUserName1 { width: 400px; line-height: 32px; color: Red !important; font-weight: bold; background-color: #669999; } Please help me...Its creating a heap of confusion..

Srivastava
  • 3,500
  • 12
  • 46
  • 74

3 Answers3

2

You should avoid using !important; were you can. Basically it is recommended that you use it only when you are overriding some pre-loaded styles that you can't really change.

ID is basically superior to class. Check the answer marked as correct here: CSS class priorities

Community
  • 1
  • 1
jayarjo
  • 16,124
  • 24
  • 94
  • 138
1

Skin probably uses inline CSS in style attribute of your control this way due to CSS herarchy what you define in skin theme will override what you have defined in class which resides external .css file.

Best way to debug CSS and HTML is viewing the code itself.

eugeneK
  • 10,750
  • 19
  • 66
  • 101
  • You didnt tellanything about the !important which when i m using in the CSS class in the corresponding property for the control,then inspite of taking the skin ID property it takes CSS class property.. – Srivastava Sep 15 '10 at 07:22
  • @Srivastava, i don't know what exactly you did override with !important tag. !important would override css property on the same hierarchy level, if you set these on different levels result may vary. Try to avoid using !important especially when you don't know how Skins in ASP.NET set css properties. – eugeneK Sep 15 '10 at 10:41
0

There is another solution - Use StyelSheetTheme attribute. When applying your theme in the web.config or (page) file as Theme attribute:

<pages Theme="myTheme">

any local cssClass control will be overridden.

However:

<pages StyleSheetTheme="myTheme">

will be secondary meaning the control will keep its assigned cssClass attribute.

So, unfortunately you can't have both (it would have been nice), but you can at least make the theme the secondary choice instead of having the theme override local cssClass settings.

Joakim Poromaa Helger
  • 1,261
  • 10
  • 17