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 over 9 years ago

2 answers

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.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">
        <style type="text/css" media="screen">
                background-color: blue;
                width: 90px;
                height: 90px;
        <div id="example">
            &nbsp;  <!-- add a non breaking space &nbsp;  and an html comment so the div isn't empty -->
Answered over 9 years ago by Tony Crockford
  • interesting &nbsp; is removed by the code syntaxer Tony Crockford over 9 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 over 9 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 over 9 years ago
Rob 230

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

Answered over 9 years ago by Rob