粘性页脚,调整图像大小附加到页脚

发布于 2024-10-05 17:18:59 字数 544 浏览 0 评论 0原文

我正在开发一个使用 960 网格的网站。在网站的底部,页面内容和页脚之间有一个 div,其中包含宽度为 100% 的图像,因此它会根据浏览器宽度调整大小。您可以在此处查看演示: http://redone.org/_dev/ski/menu2.html

上面的内容很好,因为内容很长。然而,在内容较短的页面上,图像和页脚会向上爬升,从而在页脚和浏览器底部之间显示出不需要的空间(单击顶部导航中的“菜单 1”或上面提供的链接中的徽标)。进入主页后,调整大小以查看页脚下方的问题。

我想使用类似于 CSS Sticky Footer 方法 (cssstickyfooterDOTcom) 的方法。

由于调整图像大小(这是所需的),我很难解决这个问题。我想我可能需要利用 jQuery 来更新页脚的高度/偏移量,因为图像高度会发生变化。

任何帮助将不胜感激。

PS 抱歉上面的链接很奇怪。我是这个论坛的新手,他们只让我发布一个链接,没有图像来直观地解释我的问题。

I'm working on a site that utilizes the 960 grid. At the bottom of the site there's a div between the page content and the footer that contains an image with a 100% width, so it resizes based on browser width. You can check out a demo here: http://redone.org/_dev/ski/menu2.html

The above works fine because the content is long. However, on pages where the content is short, the image and the footer creep up to reveal undesired space between the footer and the bottom of the browser (click "MENU 1" in the top nav or the logo in the link provided above). Once on the homepage, resize to see issue below footer.

I'd like to utilize a method similar to the CSS Sticky Footer method (cssstickyfooterDOTcom).

I'm having a difficult time solving this due to the resizing of the image (which is desired). I think I might need to utilize jQuery to update the height/offset of the footer, as the image height changes.

Any help would be greatly appreciated.

P.S. Sorry about the link weirdness above. I'm new to this forum and they'll only let me post one link and no images to visually explain my issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔岸观火 2024-10-12 17:18:59

像这样的事情应该可以解决问题。相对定位主体,以便可以将页脚固定到底部。与图像相同。现在,当窗口高度超过主体高度时,将主体高度设置为窗口高度,以便页脚保持在底部。

CSS

body            {position: relative}
.footer         {position: absolute; bottom: 0px}
.imgbackground  {position: absolute; bottom: [footer height]}

JS

$(window).resize(function() {
    var winHeight = $(this).height();
    if(winHeght > $('body').height()) 
        $('body').height($(this).height()); // set the body height to the window height
    else $('body').height('auto'); 
}).resize();

Something like this should do the trick. Position the body relative so you can tie the footer to the bottom. Same with the image. Now, when the window height exceeds the body height, set the body height to the window height so the footer stays at the bottom.

CSS

body            {position: relative}
.footer         {position: absolute; bottom: 0px}
.imgbackground  {position: absolute; bottom: [footer height]}

JS

$(window).resize(function() {
    var winHeight = $(this).height();
    if(winHeght > $('body').height()) 
        $('body').height($(this).height()); // set the body height to the window height
    else $('body').height('auto'); 
}).resize();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文