How can I change an attribute of all the elements without them having their id? What do I mean? Lets say I have 5 divs and 4 tables on a document but non of them have an id tag and I want to change the background of all divs. Can I do that? For test I put the following line at the end of the document and it worked: <style>div{background-color:blue;}</style> PHP: But the problem is that it is not validated. So how do I do that?
That's not the way stylesheets work. CSS is not javascript, to be run in place. You really must learn how to use selectors, inheritance and the cascade. In the meantime, use the style attribute, <p style="color: red;"> ... </p>. That's a poor practice, but it'll get you by while you study. cheers, gary
Sorry for the delayed response. Using inline styles is certainly legal, but is counter to good practices[1]. Better would be to assign a class or id to the element, then apply style rules in the stylesheet. If you mix styles and html (presentation and structure), you're left having to edit every case should you decide on some different style. Consider: You've decided that an occasional word or phrase should be hi-lited in some manner (strictly typographical, not semantic or structural), so you insert the style attribute into a span tag that makes the marked text a blinking red. Now, for some reason, you gain a modicum of clue and realize just how stupid the blink is. How many times in your site did you use it? As you go from page to page editing, did you catch every instance? Now consider a good practice scenario: Each targeted word or phrase's span tag has a class attribute of, say, "special". Now to make the change, you only need to edit the one style rule set in one file. Even if you only used the rule a single time, it's just as easy to do it correctly as do it poorly, and you won't have to remember which file has the blinking red text. cheers, gary [1] The same applies to javascript. Inlining javascript (behavior) is also poor practice. Best practice is to completely separate behavior (javascript) and presentation (css) from structure ((x)html).