Solved

using css on div margins

Posted on 2016-07-15
3
55 Views
Last Modified: 2016-07-15
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?
0
Comment
Question by:maqskywalker
3 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
Comment Utility
Add this to your CSS
 body
 {
   margin: 0;
 }

Open in new window

1
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Russ is right.  <body> has a default margin of 4 to 8 pixels depending on the browser.
0
 
LVL 1

Author Closing Comment

by:maqskywalker
Comment Utility
thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Run Script only if a div is in the viewport 6 28
Menu Inconsistent 3 18
Login area of a page 4 18
Different Delete Messages 7 10
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now