5

I'm using a combination of two classes on a span element.

Both look like they're working by themselves... Together they're not.

.black {color:black;}
.size_14 {font-size:14px;}


<span class="black size_14">my text is not black..neither large</span>

I tried changing the size_14 class name for another one (large) and in this case it is working.

Is size_14 an invalid class name?

SOLVED

I was overriding the behaviour with

.article_text_div .size_14 {color:#6D6E71;}

But thanks to this mistake I discovered It's better(?) not to use underscores inside class names

Double thanks

Luca

6
  • 1
    size_14 is a perfectly valid class name. stackoverflow.com/questions/448981/… but browser support is spotty. Commented May 6, 2011 at 17:09
  • Please show the complete page. If you've typed them together like what you've shown, they'll never work. Commented May 6, 2011 at 17:11
  • 3
    Your code worked for me - jsfiddle.net/N26ee Commented May 6, 2011 at 17:13
  • Hi Luca. Out of curiosity, on which browser? Commented May 6, 2011 at 17:24
  • Not browser depending is very cross browser!.. Commented May 6, 2011 at 17:26

4 Answers 4

4

That example seems to work fine. There must be another rule that is overriding your change. Check the CSS with Firebug or a similar inspector, it will tell you exactly which classes are being used and overridden.

Sign up to request clarification or add additional context in comments.

Comments

2

Underscores are not recommended in class names and ID's. Support is mixed across the board. I would remove it or replace it with a dash.

1 Comment

That's from 2001, and is talking is about browsers like IE5 and Opera 5.
0

If I were you I'd be inclined to try the following, but without seeing the rest of the code it's difficult to tell if it'll make a difference..

.black{color:black;}
.size-14, span.size-14{font-size:14px;}

Comments

0

You can use underscore, article in above comment was written in 2001. All latest browser supports use of _. But most developer prefer to use "-" for class names.

http://jsfiddle.net/ZsR4A/embedded/result/

Works as expected in IE, FF, Chrome. Make sure your size_14 has higher specificity.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.