(html/css)需要全宽页眉/页脚帮助:三面空白/空白
这个问题对于任何想要构建一个带有全宽页眉和/或页脚的简单html页面的业余爱好者/初学者来说都很有帮助 我是这样的业余爱好者,试图帮助一个朋友建立一个零预算的网站 我使用的是Kompozer/NVU,以防与答案相关 当你听到/看到我这样做时,请不要畏缩,不知道我冒犯了多少html或css神;-)我的问题也将是简单的英语,很少或没有适当的术语…你已经得到警告 [mods注意:我还敢绕过你的垃圾邮件保护新手规则,最多2个链接,因为我没有程序员语言,一个链接可以帮助澄清我的问题,因此我希望这对每个人都有利。没有垃圾邮件,承诺!] 我的具体目标: 我希望我的页眉和页脚(在本页:)为(html/css)需要全宽页眉/页脚帮助:三面空白/空白,html,css,header,margin,footer,Html,Css,Header,Margin,Footer,这个问题对于任何想要构建一个带有全宽页眉和/或页脚的简单html页面的业余爱好者/初学者来说都很有帮助 我是这样的业余爱好者,试图帮助一个朋友建立一个零预算的网站 我使用的是Kompozer/NVU,以防与答案相关 当你听到/看到我这样做时,请不要畏缩,不知道我冒犯了多少html或css神;-)我的问题也将是简单的英语,很少或没有适当的术语…你已经得到警告 [mods注意:我还敢绕过你的垃圾邮件保护新手规则,最多2个链接,因为我没有程序员语言,一个链接可以帮助澄清我的问题,因此我希望这对每个人都
<div id="mastercontainer">
<div id="header">This is the header</div>
<div id="content">
<div id="innercontentmiddle">
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
<p>This is some content</p>
</div>
</div>
<div id="footerclear"></div>
</div>
<div id="footer">This is the footer</div>
基本上我们在这里说的是,我们希望我们的主容器是可用空间宽度和高度的100%。它包括一个页眉和内容以及一个footerclear元素(这是为了防止content中的内容流过页脚,因此在此设置一个合理的高度)。Outfooter元素位于主容器外部,100px进入主容器(以防止在没有足够内容时显示在页面外)。主容器上的页边距底部必须始终与页脚的高度相同才能起作用
为了进一步阅读,我一直喜欢布局
编辑1
如果页眉和页脚周围仍然有间距,那么很可能是主体元素的边距/填充。在CSS中尝试以下操作:
html, body {
height: 100%;
min-height: 100%;
color: #fff;
margin: 0;
padding: 0;
}
不是100%确定,但我认为这可能是你想要的:
我的解决方案与Delan的类似,但我现在已经编写了所有代码,因此我将发布它: 编辑:嗯,看来他删除了他的答案 HTML
<header>
<h1>MySite</h1>
</header>
<section>
<h2>Content</h2>
<p>Lorem ipsum dolor</p>
<p>Lorem ipsum dolor</p>
<p>Lorem ipsum dolor</p>
<p>Lorem ipsum dolor</p>
</section>
<footer>
<p>Copyright © 2012</p>
</footer>
除非您将页眉和页脚都设置为固定高度,否则您需要使用JS计算它们的高度,并相应地更改内容区域边距:
$(function () {
var headerHeight = $('header').outerHeight();
var footerHeight = $('footer').outerHeight();
$('section').css({
marginTop: headerHeight + 'px',
marginBottom: footerHeight + 'px',
});
});
Edit2:在一个大型站点(不是JSFIDLE示例)上,我会给出这些元素的ID和样式以及脚本,因为您可能会使用多个
标题
,页脚
和部分
请在此处发布相关代码。回答你的问题:你用桌子来布置,现在它咬你的屁股。这样的事情应该让你开始:首先,我想表达我对这个社区的感谢,你们所有人都对一个陌生人如此友好地回应,尤其是一个显然没有任何东西可以回馈这个特殊社区的人。我不知道你是否还意识到这有多特别…谢谢你。Terric,你的小提琴似乎正是我想要的,你的代码肯定改进了我的工作,谢谢你…但是,我仍然在页眉和页脚(页眉/f)周围获得相同的空间
header,
footer {
background: #06c;
text-align: center;
/* Makes the header and footer stick to the top */
position: fixed;
left: 0;
top: 0;
width: 100%;
}
footer {
/* We want the footer in the bottom */
top: auto;
bottom: 0;
}
section {
background: #eee;
/* Centers the content area (margin: 0 auto) */
width: 70%;
margin: 0 auto;
/* Here's the tricky bit, the margin-top needs to be exactly the height of the header (which may not be known) and the margin-bottom needs to be the height of the footer - I'm using an arbitrary number here and setting it properly with JS */
margin-top: 15px;
margin-bottom: 15px;
}
$(function () {
var headerHeight = $('header').outerHeight();
var footerHeight = $('footer').outerHeight();
$('section').css({
marginTop: headerHeight + 'px',
marginBottom: footerHeight + 'px',
});
});