im trying to use divs but its not working. heres what the html code looks like: < div id="example"> < div/> thats the html code but without the spaces. and the css code is this: #example (background:blue; width: 90px; height: 90px;) for some reason i cant see the div on the page. what am i doing wrong?

  • Your div code looks malformed, it should be: < div id="example"> < /div> Stephen almost 8 years ago

2 answers

0
points
This was chosen as the best answer

you might also have problems with the lack of content in the div - some browsers will not render empty divs.

try:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <style type="text/css" media="screen">
            #example{
                background-color: blue;
                width: 90px;
                height: 90px;
            }
        </style>
    </head>
    <body>
        <div id="example">
            &nbsp;  <!-- add a non breaking space &nbsp;  and an html comment so the div isn't empty -->
        </div>
    </body>
</html>
Answered almost 8 years ago by Tony Crockford
  • interesting &nbsp; is removed by the code syntaxer Tony Crockford almost 8 years ago
  • If you've set a width and height then I'm sure all browsers (even IE6) will render the div properly, regardless of content. DisgruntledGoat almost 8 years ago
  • true, but IE will do weird and wonderful things with an empty div and width: auto; for predictable results empty divs should be avoided IME Tony Crockford almost 8 years ago
Rob 230
3
points

Remove the parenthese and replace them with curly brackets {} . Also, end tags are < /div>, not as you have it.

Answered almost 8 years ago by Rob