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

前端 未结 17 1049
眼角桃花
眼角桃花 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:23

    A lot of elements in CSS have default padding and margins set on them. So, when you start building a new site, it's always good to have a reset.css file ready. Add this to make to rub the default values, so you have more control over your web page.

    /* CSS reset */
    body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { 
        margin:0;
        padding:0;
    }
    html,body {
        margin:0;
        padding:0;
    }
    
    
    /* Extra options you might want to consider*/
    
    table {
        border-collapse:collapse;
        border-spacing:0;
    }
    fieldset,img { 
        border:0;
    }
    input{
        border:1px solid #b0b0b0;
        padding:3px 5px 4px;
        color:#979797;
        width:190px;
    }
    address,caption,cite,code,dfn,th,var {
        font-style:normal;
        font-weight:normal;
    }
    ol,ul {
        list-style:none;
    }
    caption,th {
        text-align:left;
    }
    h1,h2,h3,h4,h5,h6 {
        font-size:100%;
        font-weight:normal;
    }
    q:before,q:after {
        content:'';
    }
    abbr,acronym { 
        border:0;
    }
    

    I hope this helps all fellow developers this is something that bugged for me a while when I was learning.

提交回复
热议问题