【问题标题】:html 100% width header and footer [duplicate]html 100% 宽度的页眉和页脚 [重复]
【发布时间】:2013-04-13 15:36:07
【问题描述】:

我正在设计一个网站,我希望我的页眉和页脚 div 跨越页面的 100% 宽度,并从页面的绝对顶部和底部开始,没有空格

我目前有这个。

<title>Untitled Document</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=PT+Sans+Narrow);

#header {
    background: #636769;
}

#navigation {
}

body {
    font-family: 'PT Sans Narrow', sans-serif;
    font-size: 16pt;
    background: url(../images/texture.png);
}

#wrapper {
    width: 938px;
    margin: 0 auto;
    padding: 20px 20px;
    background: white;
}

#footer {
   background: #636769;
}
</style>
</head>



<body>
<!-- begin header -->
  <div id="header">
    <p>Content</p>
  </div>

<!-- begin wrapper -->
<div id="wrapper">

<!-- begin navigation -->
  <div id="navigation">
    <ol>
    <li>link1</li>
    <li>link2</li>
    <li>link3</li>
    <li>link4</li>
    </ol>
  </div>

<!-- begin content -->
  <div id="content">
    <h1>Heading</h1>
    <p>Content</p>
  </div>

</div>

<!-- begin footer -->
  <div id="footer">
    <p>Content</p>
  </div>

</body>
</html>

我希望页眉和页脚看起来像这样; http://rocketbug.com/2.0/

谢谢你,尼尔。

【问题讨论】:

    标签: html css header width footer


    【解决方案1】:

    您可能需要覆盖body 元素的margin(例如,Chrome 会将其设置为 8px。

    【讨论】:

      【解决方案2】:

      在顶部添加css:

      * {
       margin:0px;
       padding:0px;
      }
      

      标题:

      #header {
          background: #636769;
          position:relative;
          width:100%;
      }
      

      页脚:

      #footer {
         background: #636769;
          width:100%;
          position:relative;
          bottom:0px;
      }
      

      【讨论】:

        【解决方案3】:
           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,
           b, u, i, center,
           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;
            vertical-align: baseline;
            background: transparent;
        }
        body {
            line-height: 1;
        }
        ol, ul {
            list-style: none;
        }
        blockquote, q {
            quotes: none;
        }
        blockquote:before, blockquote:after,
        q:before, q:after {
            content: '';
            content: none;
        }
        
        /* Don't kill focus outline for keyboard users: http://24ways.org/2009/dont-lose-your-focus */
        a:hover, a:active {
            outline: none;
        }
        
        /* remember to highlight inserts somehow! */
        ins {
            text-decoration: none;
        }
        del {
            text-decoration: line-through;
        }
        
        /* tables still need 'cellspacing="0"' in the markup */
        table {
            border-collapse: collapse;`enter code here`
            border-spacing: 0;
        }
        #header {
            background: #636769;
        }
        
        #navigation {
        }
        
        body {
            font-family: 'PT Sans Narrow', sans-serif;
            font-size: 16pt;
            background: url(../images/texture.png);
            position: relative;
        }
        
        #wrapper {
            width: 938px;
            margin: 0 auto;
            padding: 20px 20px;
            background: white;
        }
        
        #footer {
           background: #636769;
            position: absolute;
            bottom: 0;
            width: 100%;
        }
        

        【讨论】:

        • 在css中添加这个,总是添加这个css来初始化所有元素html的所有css,看这个例子:jsfiddle.net/ARuvu
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-13
        • 2013-04-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-03
        • 2014-07-05
        相关资源
        最近更新 更多