css - 包装背景图像在顶部被截断

标签 css image background position

我的网站有一个包含三个背景图像的包装器。静态顶部和底部图像以及沿 y 轴重复的第三个图像。出于某种原因,最上面的背景图片被截断了,我想不出办法。

这是实时站点的链接:http://storrepictures.weebly.com/projects.html

我已经偏移了顶部和底部的图像,这样您就可以看到它们的样子。你可以看到上面的那个被切断了。我试过弄乱一些 div 填充设置,但似乎无法让它工作。

一个有趣的注意事项:背景图像曾经是 JPEG(我切换到 PNG 文件,因为我需要透明度)。当我使用 JPEG 时,这不是问题 - 三张图像完美对齐。

让我知道发布实际代码是否有帮助。从我在这个论坛上读到的内容来看,人们似乎喜欢看现场直播的网站,我不想让帖子太长。

非常感谢您的帮助。

*这是 CSS:

body {

background: #ffffff;
font-family: Tahoma, arial, sans-serif;
font-size:12px;
color:#666666;
margin: 0;
padding: 0;
}


#wrapper {
    background: url(containerbg.png) center repeat-y;

}

#wrappertop{
background: url(containertop.png) no-repeat;
background-position: 0px -40px; 
}

#wrappertbtm{
background: url(containerbtm.png)   no-repeat;
background-position: 34px 480px;
padding-bottom: 65px;
}
.title{
width: 1022px;
min-height: 30px;
_height: 30px;
padding: 10px 0px 10px 0px;
font-size: 30px;
}

.title, .title a {
color: #fff;
}


#container {
width: 100%;
position: relative;
top: 125px;
bottom: 0px;
margin: 0px;
padding: -300px 0px 0px 0px;
}

#content{
width: 800px;
min-height: 500px;
_height: 500px;
margin: 0pt auto;

}

#content a{
color: #ff6633;
text-decoration: none;
}
.weebly_header{
background: url(%%HEADERIMG%%) no-repeat;
}

这是 HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>{title}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--[if lt IE 7]> 
<style>
    #content
{
    height:400px !important;
} 
</style>
<![endif]-->
</head>
<body class="wsite-theme-light">
    <div id="wrapper">
      <div id="wrappertop">
        <div id="wrappertbtm">
            <div id="container">
                 <div id="header">
                   <div id="headerleft">{logo max-height="60"}</div>
                   <div id="navigation">{menu}</div>        
             </div> 


        <div id="content">{content}
            <div id="footer">{footer}

            </div>
            </div>
            </div>
            </div>
            </div>
</div> 
</div>

最佳答案

据我所知,您的 body 元素有 paddingmargin 值干扰:

body {
    background: url(theme/backgroundtop.jpg?909894) left top repeat-x, 
        url(theme/backgroundbottom.jpg?909894) left bottom repeat-x, 
        url(theme/backgroundmid.jpg?909894) left repeat;
    font-family: Tahoma, arial, sans-serif;
    font-size: 12px;
    color: #666666;
    height: 100%;
    margin: 100px 0 0 0;
    padding: 100px 0 0 0;
}

你应该摆脱这些规则:

body {
    /* ... */
    margin: 0;
    padding: 0;
}

一切都应该没问题。

注意:为 body 元素设置 height: 100% 是没有意义的,您可能也想删除它。

注意#2:对于正文的多个背景,您只有 3 个值,这些值将被解析为 T/LR/B,而顺序或这些值表明您应该更改它们的顺序,即 backgroundtop/backgroundmid/backgroundbottom 而不是 backgroundtop/backgroundbottom/backgroundmid

关于css - 包装背景图像在顶部被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9862306/

相关文章:

javascript - 如何在动画之前延迟 .css 函数

html - 溢出自动/滚动在具有巨大 innerhtml 值的 FF 中无法正常工作

javascript - Bootbox 模式在打开前滚动到页面顶部

javascript - 仅在一个 div 上使用 jInvertScroll.js

html - 如何将图像居中对齐?

ios - 自定义 UIButton isSelected 背景颜色未按预期工作(IOS/Swift)

asp.net - Crystal Report Viewer 控件未加载报表内的图像

image - 在JAVA中使用Opencv模糊图像

android - Android 中的 GridView 行背景图片

css - Sprite 图像的响应式悬停效果 - 无法使其工作