固定顶部而不是上方的标头

Thr*_*eaT 0 html css html5 css3

我试图在页面顶部获得一个固定的标题,但由于某种原因,它继续在容器的顶部.当我使用margin-bottommargin-top然后它仍然坚持容器.

index.css

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, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
        margin: 0;
        padding: 0;
        border: 0;
        font-size: 100%;
        font: inherit;
        vertical-align: baseline; 
}
.full-container {
    width:100%;
}
.boxborder {
    -webkit-box-shadow:inset 0px 0px 0px 10px black;
    -moz-box-shado:inset 0px 0px 0px 1px black;
    box-shadow:inset 0px 0px 0px 1px black;
}
.header {
    height: 150px;
    margin-bottom: 20px;
    position: fixed;
}
.container {
    position: relative;
    margin-left: auto;
    margin-right: auto;
    width: 800px;
    height: 1200px;
}
Run Code Online (Sandbox Code Playgroud)

的index.html

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" href="index.css">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div class="full-container header boxborder"></div>
        <div class="container boxborder"></div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

rei*_*der 6

你需要在你的CSS中定义topleft.header

  • 我同意,我只是认为在这里添加它会很好,它可能有助于@ThreaT了解这些属性实际上做了什么. (2认同)