我正在尝试创建一个横跨屏幕宽度的页脚。它嵌套在宽度为 825px 的 body 标签中(通过使用 margin left/right auto 居中),所以我将它取出并嵌套在 html 标签下,从而消除了宽度限制。
不过现在看起来是页脚元素与左下角居中的 body 标签对齐。我希望它从屏幕的最左侧开始。
我必须怎么做才能让页脚元素从左到右横跨整个屏幕宽度?
您不希望页脚位于 HTML 标记之外。这样的事情应该有效。
如果您在 body 标签上设置了宽度,则 100% 只会扩展到标签上设置的宽度。另外,如果您打算使用 HTML5,我建议您使用 <footer></footer>
标签。请记住,HTML5 需要 hack 才能在旧版浏览器上工作。
<style type="text/css">
body {/*use this to declare font-family and other common attributes */}
#header {width:825px;height:200px;margin:0 auto 0 auto}/*or whatever your dimensions are*/
#main-content-wrapper {width:825px;margin:0 auto 0 auto;}
#footer {width:100%;}
</style>
<html>
<head>
<title></title>
<head>
<body>
<div id="header"></div>
<div id="main-content-wrapper"></div>
<div id="footer"></div>
</body>
</html>
我是一名优秀的程序员,十分优秀!