边距如何与 div 定位配合使用?
#content
div 包含大部分网页内容。 如下所示,上边距为 280px,因为这是网站标题图像的高度,该图像放置在“正文”中作为背景 (image/sky1.jpg)。
如何将 div 作为支架放置在 #content
div 的“边距”上方,以便可以放置我的 #navigation
、#Title
标题图像上方的 div?
#content div 上方的 #top-float
div 是它的开始,但每次我添加更多的高度时
“保证金”受到影响,将其推低。
我尝试将 之上在 html 中,我应该如何定位它?
html {
background: #73ADD7 url(images/gradient.gif) repeat-x;
}
body {
padding: 0;
margin: 0;
background:url(images/sky1.jpg) no-repeat center top;
color: #666;
width: 100%;
display: table;
}
#top-float{
padding-left:2.3em;
padding-right:2.3em;
height:10em;
}
#content {
width: 890px;
margin: 280px auto 0;
background: #fff;
border: solid 0px #ccc;
padding: 0px;
}
#footer {
width: 890px;
margin: px auto 0;
background:url(images/footer-bg.jpg)
no-repeat center bottom #fff;
border: solid 0px #ccc;
height:250px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
最简单的方法是将
#top-float
的高度设置为280px
并降低#content< 的
top-margin
/code> 如下:如果您需要
em
大小调整,则为#top-float
的子级调整 em 大小,并确保给予#top-float
overflow:hidden;
如果您希望内容显示在标记中的标题上方以实现 SEO 目的,您可以执行以下操作:
The easiest way would be to give your
#top-float
a height of280px
and drop thetop-margin
for#content
as such:If you need
em
sizing, then give the children of#top-float
em sizing, and make sure to give#top-float
overflow: hidden;
If you want your content to appear above your header in your markup for SEO purposes, you can do the following:
只需删除内容 div 的上边距,并在其上方添加指定高度的占位符即可。
HTML 片段:
和 CSS:
如果将额外的标头信息放在内容 div 内(语义上)更有意义,则可以使用负边距。
HTML 片段:
和 CSS:
Just remove the top margin from your content div, and add the placeholder above it with the height specified.
HTML snip:
And CSS:
If it makes more sense for the extra header information to be within the content div (semantically), you can use a negative margin.
HTML snip:
And CSS:
在没有看到 HTML 的情况下回答这个问题有点棘手,但有一些建议:
一如既往,没有一种方法可以实现此目的。
It is a little tricky answering this without also seeing your HTML, but a few suggestions:
As always, there is no one way of accomplishing this.
您可能希望为 #top-float div 使用绝对或固定定位。
为什么要把标题图片作为背景图片呢? 我想您会发现,如果您不将网站的标题图像作为背景,一切都会变得更容易。 单击网站的徽标(我假设位于您的标题图像中)会将用户带回主页也是常见的做法。 将网站的徽标设置为背景图像会有效地禁用此功能。
You may want to use absolute or fixed positioning for your #top-float div.
Why do you want to put the header image as a background image? I think you'll find that it all works out easier if you don't put the site's header image as a background. It is also common practice that clicking on the site's logo (which I assume is in your header image) takes the user back to the home page. Making the site's logo a background image effectively disables this feature.