using css on div margins

I have this html code

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type="text/css">
        #mydiv {
            background-color: #304bee;
            height: 400px;
            width: 100%;
        }

        #mytable {
            height: 100px;
            width: 200px;
            border: 1px solid #00ff00;
            /* center horizontally */
            margin-left: auto;
            margin-right: auto;
        }
    </style>
</head>
<body>
    <div id="mydiv">
        <table id="mytable">
            <tr>
                <td>your table
                </td>
            </tr>
        </table>
    </div>
</body>
</html>

Open in new window


When I run that in google chrome it looks like this:

running the page in chrome
I set the width of my div to 100% but notice how there still some space to the left and right of the div.

How would i get rid of the space to the left and right of the div?
LVL 1
maqskywalkerAsked:
Who is Participating?
 
Russ SuterConnect With a Mentor Commented:
Add this to your CSS
 body
 {
   margin: 0;
 }

Open in new window

1
 
Dave BaldwinFixer of ProblemsCommented:
Russ is right.  <body> has a default margin of 4 to 8 pixels depending on the browser.
0
 
maqskywalkerAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.