Help with CSS?

Hi I am just starting to learn cascading style sheets, and not really getting the difference between div, classes and ID's. Can someone explain? Thanks.

Public Comments

  1. A <div> is a block-level element, which means it's a container that has a line break after it. A class is a way to identify styles which can be applied to many elements (like multiple divs). An id is a unique identifier used to refer to only one particular element (like a single div). Here's an example: <div>some text</div> <div class="foo">some more text</div> <div class="foo" id="bar">even more text</div> div { color: red; } .foo { text-decoration: underline; } #bar { font-weight: bold; } With this particular combination of HTML and CSS, text in all the divs will be red, text in the second and third will be underlined, and the text in the last div also be bold. Also, keep in mind that element-level styles are overridden by class-level styles, which are overridden by id-level styles. Consider this example: div { color: red; } .foo { color: blue; } #bar { color: green; } Using our previous HTML example, the first div will have red text, the second will have blue text, and the third will have green text.
Powered by Yahoo! Answers