How to margin the body of the page (html)?

后端 未结 8 1683
萌比男神i
萌比男神i 2020-12-15 18:14

I used the following


which works only on IE6. I want it to work with firefo

相关标签:
8条回答
  • 2020-12-15 18:28
    <body topmargin="0" leftmargin="0" rightmargin="0">
    

    I'm not sure where you read this, but this is the accepted way of setting CSS styles inline is:

    <body style="margin-top: 0px; margin-left: 0px; margin-right: 0px;">
    

    And with a stylesheet:

    body
    {
      margin-top: 0px;
      margin-left: 0px;
      margin-right: 0px;
    }
    
    0 讨论(0)
  • 2020-12-15 18:33

    Html for content, CSS for style

    <body style='margin-top:0;margin-left:0;margin-right:0;'>
    
    0 讨论(0)
  • 2020-12-15 18:35

    You need to use css. It's how modern web design gets things done.

    This is a basic css walk through.

    Your html file would be like:

    (really simple html)

        <html>
        <head>
        <link rel="stylesheet" type="text/css" href="mystyle.css" />
        </head>
        <body>
        </body>
        <html>
    

    Your css file (mystyle.css) would look like:

    body 
    {
     margin-top:0px;
     margin-left:0px;
     margin-right:0px;
    
    }
    
    0 讨论(0)
  • 2020-12-15 18:41

    Yeah a CSS primer will not hurt here so you can do two things: 1 - within the tags of your html you can open a style tag like this:

    <style type="text/css">
      body {
       margin: 0px;
      }
      /*
       * this is the same as writing
       * body { margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;}
       * I'm adding px here for clarity sake but the unit is not really needed if you have 0
       * look into em, pt and % for other unit types 
       * the rules are always clockwise: top, right, bottom, left
      */
    </style>
    

    2- the above though will only work on the page you have this code embeded, so if if you wanted to reuse this in 10 files, then you will have to copy it over on all 10 files, and if you wanted to make a change let's say have a margin of 5px instead, you would have to open all those files and make the edit. That's why using an external style sheet is a golden rule in front end coding. So save the body declaration in a separate file named style.css for example and from your add this to your html instead:

    <link rel="stylesheet" type="text/css" href="style.css"/>
    

    Now you can put this in the of all pages that will benefit from these styles and whenever needed to change them you will only need to do so in one place. Hope it helps. Cheers

    0 讨论(0)
  • 2020-12-15 18:42

    For start you can use:

    <body style="margin:0;padding:0">
    

    Once you study a bit about css, you can change it to:

    body {margin:0;padding:0}
    

    in your stylesheet.

    0 讨论(0)
  • 2020-12-15 18:45

    I hope this will be helpful.. If I understood the problem

    html{
         background-color:green;
    }
    
    body {
        position:relative; 
        left:200px;    
        background-color:red;
    }
    div{
        position:relative;  
        left:100px;
        width:100px;
        height:100px;
        background-color:blue;
    }
    

    http://jsfiddle.net/6M6ZQ/

    0 讨论(0)
提交回复
热议问题