【问题标题】:Background picture not working with fixed attachment背景图片不适用于固定附件
【发布时间】:2011-04-01 19:18:12
【问题描述】:

我正在处理一个项目,但遇到了障碍,我似乎无法解决这个问题。 (哈哈,修复)

我有一个与 html、php 的 <?php include=""; ?>、javascript(和 jQuery)一致的页面,当然还有一些 CSS。问题在于 CSS。

首页有one background picture,子页面有another background picture

子页面的图片应该放在“右上方”,首页图片应该放置在显示整个图片的位置。

当没有指定background-attachment: 时它工作得很好,但是我有一个子页面,它的文本比页面可以包含的要多。当然,这会使页面滚动。我希望图片不移动(保持固定),但是当我在 css 中将“固定”添加到我的 background: 时,图片变得疯狂。这是命令,我把我的东西放在background:

div#container {
    background: #ccffff url("billder/bckground.jpg") fixed no-repeat right top;
}

我认为问题可能出在此处,但我尝试将标签分开,或者在 css 中调用它,如下所示:

background-color: #ccffff;
background-image: url("billeder/bckground.jpg");
background-attachment: fixed;
background-repeat: no-repeat;
background-position: right top;

仍然不工作(仍然wild

我使用this method 构建页面以使div 具有min-height: 的百分比。 This is the main page 我的项目和 this is the subpage 有很多文字。如您所见,主页面疯狂,子页面的背景图片无法正确显示,您无法看到整个图片。图片固定,但未按我想要的方式显示。

我真的希望你能帮助我,因为我已经为这个网站付出了很多的努力。

为了避免任何误解和烦人的问题,我不是一个非常有经验的程序员/网络开发人员。

编辑

为了清楚起见,我想要的是背景保持固定(与页面一起滚动)

【问题讨论】:

    标签: css background


    【解决方案1】:

    删除fixed 并将min-height(或我认为更好看的height)设置为750px <div id="container_front">...</div>

    所以它在你的 css 中变成了这个:

    div#container {
        position:relative;
        margin:0 auto;
        width:900px;
        background-color: #ccffff;
        background-image: url("billeder/bckground.jpg");
        background-repeat: no-repeat;
        background-position: right top;
        background-attachment: fixed;
        height: 750px;
        min-height: 750px;
    }
    

    【讨论】:

    • 修复不在css代码中时工作(就像以前一样),但是图片没有像我想要的那样固定:)我希望图片跟随向下滚动时的页面
    • 我使用 min-height 的原因是,高度(在“真实”浏览器中,不是 IE)不允许容器扩大大小:)
    • 我以为你想要那个 - 2 秒。你应该知道背景的大小对于大屏幕(比如我的)来说不够高
    • 哦!我会尽快修复(哈哈,再次修复):)
    • 这就是你想要的:stackoverflow.com/questions/2262565/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    相关资源
    最近更新 更多