How do I remove the top margin in a web page?

前端 未结 17 973
眼角桃花
眼角桃花 2020-11-29 02:26

I have had this problem with every web page I have created. There is always a top margin above the \'main container\' div I use to place my content in the center of the pag

相关标签:
17条回答
  • 2020-11-29 03:08

    You can prevent the effects of margin collapsing with:

    body { overflow: hidden }
    

    That will make the body margins remain accurate.

    0 讨论(0)
  • 2020-11-29 03:09

    I had similar problem, got this resolved by the following CSS:

    body {    
        margin: 0 !important;
        padding: 0 !important;
    }
    
    0 讨论(0)
  • 2020-11-29 03:12
    style="text-align:center;margin-top:0;" cz-shortcut-listen="true"
    

    paste this at your body tag!

    this will remove the top margin

    0 讨论(0)
  • 2020-11-29 03:16

    It is a <p> element that creates the top margin. You removed all top margins except of that element.

    0 讨论(0)
  • 2020-11-29 03:16

    body{
    margin:0;
    padding:0;
    }
    <span>Example</span>

    0 讨论(0)
  • 2020-11-29 03:16

    I tried almost every online technique, but i still got the top space in my website, when ever i open it with opera mini mobile phone browser, so i decided to try fix it on my own, and i got it right!

    i realize when even you display a page in a single layout, it fits the website to the screen, and some css functions are disabled, since margin, padding, float and position functions are disabled automatically when you fit to screen, and the body always add inbuilt padding at the top. so i decieded to look for at least one function that works, guess what? "display". let me show you how!

    <html>
    <head>
    <style>
    body {
    display: inline;
    }
    
    #top {
    display: inline-block;
    }
    </style>
    </head>
    <body>
    <div id="top">
    
    <!-- your code goes here! -->
    
    eg: <div id="header"></div>
    <div id="container"></div> and so on..
    
    <!-- your code goes here! -->
    
    </div>
    </body>
    </html>
    

    If you notice, the body{display:inline;} removes the inbuilt padding in the body, but without #top{display:inline-block;}, the div still wont display well, so you must include the <div id="top"> element before any code on your page! so simple.. hope this helps? you can thank me if it works, http://www.facebook.com/exploxi

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