简体   繁体   English

如何将div粘贴到页脚?

[英]How to stick a div to the footer?

I have a menu in div.wrapper , I want the div.wrapper to stick to the footer 我在div.wrapper有一个菜单,我希望div.wrapper粘贴在页div.wrapper

<div class="wrapper">
    <div id="menu">
        <ul>
            <li>1.</li>
            <li>2.</li>
            <li>3.</li>
        </ul>
    </div>
    <div class="push"></div>
</div>

<div class="footer">
    <div id="footer-menu"></div>
</div>

How I can do that? 我该怎么做? My code jsfiddle . 我的代码jsfiddle I cant move this menu from .wrapper to .footer . 我无法将此菜单从.wrapper移到.footer If I move scroll on page I want to have this menu stick with my footer. 如果我在页面上移动滚动条,则希望此菜单栏与页脚保持一致。

Check this updated fiddle . 检查此更新的小提琴 I think this way you can achieve it. 我认为您可以通过这种方式实现它。 You don't need any JavaScript/ JQuery code to do it only CSS should be sufficient. 您不需要任何JavaScript / JQuery代码即可,仅CSS就足够了。

Changes in CSS classes : CSS类的变化:

.footer {
    position : fixed;
    bottom : 0;
    height: 155px;
    background-color : red;
    width : 100%;
}

#menu{
    position : fixed;
    bottom : 60px;
    z-index : 1;
}

position:fixed will take care of window scroll. position:fixed将照顾窗口滚动。 Take a look at bottom property added to both the classes . 看一下添加到两个classes bottom属性。 For footer it is 0 where as for menu it is 60px . footer0menu60px You can change bottom value in menu to position it the way you want. 您可以在menu更改bottom值以将其放置在所需的位置。 z-index will bring it above the footer . z-index会将其置于footer上方。

Also, you should use footer tag rather than a div with class footer . 另外,您应该使用footer 标签,而不是class footer的div。

Use like this: 像这样使用:

$('#menu').appendTo('.footer').css('position','fixed');

If you just want to move use this: 如果您只想移动,请使用以下命令:

$('#menu').appendTo('.footer');

And if you want when you scroll use something like this: 如果要在滚动时使用以下内容:

$(window).on('scroll',function(){
//code in when to move
var t = $(window).scrollTop();
if(t>300)
    $('#menu').appendTo('.footer');
});

demo 演示

demo with scroll 滚动演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM