HTML DIV Tag Position for Absolute TOP

.myDiv  
{

background-image: url(urltomyimgheader);

height:100px;

margin: auto;

position:relative;

top:-10px;

width:600px;

}

This is a simple div tag used to display a logo ...

I made top -10px so that it touches the top of the browser, where if there is no gap between the logo and the page.

However, I feel bad about using -10px to place a div :( Is there a better and cross-browser solution?

+3
source share
2 answers

@Tatu Ulmanen is right that this is a problem with the default browser. You do not need to add negative fields, you just need to set the default CSS attribute of the body / html tags.

, CSS reset, . , . , CSS reset, CSS .

html, body {
padding: 0;
margin: 0;
}

CSS Reset:   /* reset */

    html, body, div, span, applet, object, iframe,
    h1, h2, h3, h4, h5, h6, p, blockquote, pre,
    a, abbr, acronym, address, big, cite, code,
    del, dfn, em, font, img, ins, kbd, q, s, samp,
    small, strike, strong, sub, sup, tt, var,
    dl, dt, dd, ol, ul, li,
    fieldset, form, label, legend,
    table, caption, tbody, tfoot, thead, tr, th, td
                        { margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline; }
    blockquote:before,
    blockquote:after,
    q:before, q:after   { content: ""; }
    blockquote, q       { quotes: "" ""; }
    body                { line-height: 1; color: black; background: white; }
    caption, th, td     { text-align: left; font-weight: normal; }
    :focus              { outline: 0; }
    table               { border-collapse: separate; border-spacing: 0; }
    ol, ul              { list-style: none; }
+3

, 10px .

body {
   padding: 0;
}

CSS reset stylesheets reset , . .

+1

Source: https://habr.com/ru/post/1742142/


All Articles