Link to home
Create AccountLog in
Avatar of Lev Seltzer
Lev SeltzerFlag for Israel

asked on

How to get around a css *

I was asked to create a page for a client at The page uses a CSS at with has a * selector. I want to redefine the font-size of the <h2> selector for this page, but the * selector always seem to override it. I've tried !important without any change in behavior, as well as an id selector.

How can I redefine the size and color of the <h2> selector tag on this page without modifying the site-wide CSS file?

Thank you.
Avatar of rbudj
Flag of United States of America image

If you just want to override it for this page, use an inline style on each <h2>

<h2 style="font-size:24px; color:#000000;"></h2>
If you have
h2 {font-size:24px; color:#000000;}

In a stylesheet that is in the listing order after the global (*) declaration, the the more specific declaration will prevail.  If it does not, then the global declaration is not the actual problem and you need to post a link so we can look at the page and see what is being applied to the h2.

Using inline styling is not a good idea as it starts to make the page more difficult to maintain.

Avatar of Lev Seltzer


I also do not want to use in-line styles.
The links to the page and the CSS are in the original posting.
Avatar of kaufmed
Have you tried using the !important modifier?
current style on the is:
#marathon h2 {color:green !important;font-size:30px !important;}

So yes, I am using !important.
My mistake. I completely glossed over your mention of that in the OP.
The page is a mess.  Even when I bypass the invalid styling before the HTML tag it gets 59 errors in the validator.  There is no point trying to get control of the styling in a page with that many error.  Fix the page, and then a logical approach to fixing the styling issue will be more likely to work.

COBOLdinosaur: I come to this site to get help. If you want to help me by suggesting that I correct page errors first, then I appreciate that. In fact, I was able to correct most of the errors in the past few minutes.

However, please do not negate my webpage and my question. You are not required to answer the question. If you feel that you cannot give an answer due to the invalid page design, then please just ignore my question.

I personally feel that this is a minor problem and that someone out there can come up with a work-around.

Thank you.
WEBuilder - Coboldinosaur wasn't particularly tactful in his suggestion, but he is right that you needed to fix the errors before solving the CSS. The errors mess up the CSS.

You have to make sure your new CSS rule is after the * rule as the browser will obey the last rule it finds. Or try giving the body an ID or class (or a div or span or something) on this page and then assign your h2 to that element.
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Perfect. I figured it was just a simple styling error on my part. Thank you for your quick response and simple solution.

If you post in the topics where I am active and you have errors in the code, they will be pointed out.  Most of the people I help on this site are professional enough to accept the criticism as part of the learning process.  

If you prefer to make your work more difficult by not validating as the first step in problem solving, then you can expect to hear about it here, instead of from your clients when one of the errors jumps up and trashes a site.