[英]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
. footer
为0
, menu
为60px
。 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');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.