If I create a class, say .test, in a stylesheet with a rule p {color:red; }, then in a paragraph with that class I place some text, the style rule doesn't apply. But if I use in-line styling within the p tag it works ok.
Is there some CSS rule I've missed here?
Thanks for the response, Brent.
I have tried that ( font-family:"Times New Roman"; ) but it made no difference. I still can't activate a class in internal styling. It also ignores the font-family, unless I place this in in-line as well.
On closer inspection, I don't seem to be able to use ANY font-related css (font-family, font-size etc.) in internal styling, when it's in a class.
They work fine with in-line styling, but that's a bit tedious (and risky for errors). Could it be related to the (free) website I'm using, maybe not allowing certain parts of CSS?
Thanks again Brent. However, W3schools says: "If a font name contains white-space, it must be quoted. Single quotes must be used when using the "style" attribute in HTML".
I tried it anyway, but it made no difference.
Stop The Press!
I just found the problem!
The text that I gave the class to was in a <p> element that was styled. I needed the class to be p.myclass and not just .myclass.
Not sure yet if this applies when <p> is not styled.
Thanks for the help. It's nice to know I can come here for advice.
Looks like I didn't make it here in time, but you solved the problem. Yes, if you are using classes in a style sheet, you must explicitly style the tags which apply just to the class in question. The same is true for IDs.
That may work, but only because the web browser has been built to allow for common errors. However, CSS standards say that quotes are needed. The same goes for most other cases. In the command line on *NIX systems, file paths with spaces either need the spaces escaped with a backwards slash, or have the entire path quoted. It's to do with the way the parser delimits command line arguments. On command line "cd /path to/some/file" would be treated as two arguments "/path" and "to/some/file". So either "cd /path\ to/some/file" or "cd '/path to/some/file' is required. Same goes for many other languages and environments.
A forum community dedicated to tech experts and enthusiasts. Come join the discussion about articles, computer security, Mac, Microsoft, Linux, hardware, networking, gaming, reviews, accessories, and more!