简体   繁体   English

页脚不要用侧边栏更改大小

[英]Footer don't change size with my sidebar

So... I have a problem with the "position" property of my footer. 所以...我的页脚的“位置”属性有问题。

footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
z-index: 3;
}

This draw my footer on the very bottom of the page if the content is big or in the bottom of the screen if the content is small, which is what I want, but it also is inside a .wrapper div, which if opened, change the size of everything making it smaller ('cause of the sidebar now is occupying part of the screen), the thing is... How do I make my footer draw on the bottom of the page/screen and also respect the size change? 如果内容很大,这会在页的底部显示页脚;如果内容很小,这会在屏幕的底部显示页脚,这是我想要的,但是它也位于.wrapper div内(如果打开,则进行更改)使其变小的所有内容的尺寸(“侧边栏的原因现在占据了屏幕的一部分),问题是...我如何使页脚在页面/屏幕的底部绘制并同时尊重尺寸的变化?

I already did tests changing the position: absolute; 我已经做过改变position: absolute;测试position: absolute; property and with the others values of position it does the size change but it don't stay at the bottom. 属性和其他position值会改变大小,但不会停留在底部。

Sidebar: https://startbootstrap.com/template-overviews/simple-sidebar 补充工具栏: https : //startbootstrap.com/template-overviews/simple-sidebar

Thanks for your patience! 谢谢你的耐心!

This feel hacky, but I tried to do it without any js on the demo page of simple-sidebar. 这感觉很hacky,但我尝试在simple-sidebar的演示页面上没有任何js的情况下进行操作。 Inside the "page-content-wrapper" div, at the same level of the "container-fluid" div of the content I added 在“页面内容包装器” div中,与我添加的内容的“容器流体” div处于同一级别

footer{
  position: fixed;
  bottom: 0;
  width: 100%;
  margin-left: -20px;
  z-index: 3;
}

It seems that if you use left:0 the sidebar goes over the position on 20px. 看来,如果您使用left:0,则侧边栏会超过20px的位置。

I feel that to really get a nice solution you should use JS to resize your footer at the same time you toogle the sidebar. 我觉得要获得一个不错的解决方案,您应该在切换侧边栏的同时使用JS来调整页脚的大小。

Hope that it helped 希望能有所帮助

So this is my intepretation of your question: 因此,这是我对您的问题的解释:

What you need to do to get your footer to stick to the bottom is basically change all the padding-left etc. properties to the bottom fixed footer equivalent. 您需要做的就是使页脚固定在底部,基本上是将所有padding-left etc.属性更改为与底部固定页脚等效的属性。

Also, since you want a bottom variant, I assumed that you still want to be able to view all the content on the page if the bar is toggled (the example hides the content that is shifted outside the window to the right). 另外,由于您需要底部的变体,因此我假设如果切换栏,您仍然希望能够查看页面上的所有内容(该示例隐藏了向右移出窗口的内容)。 To achieve this, the page-content needs position: relative . 为此,页面内容需要position: relative


More comments can be found in the snippet below. 可以在下面的代码段中找到更多评论。

Hope it helped :) 希望它有帮助:)

 //Simulate JS from the sample site document.getElementById("menu-toggle").addEventListener("click", function(){ document.getElementById("wrapper").classList.toggle("toggled"); }) // Remove annoying margin from example box *Ignore* this for personal use document.body.style.margin = "0px"; 
 #wrapper { margin: 0; padding-bottom: 0; -webkit-transition: all 0.5s ease; -moz-transition: all 0.5s ease; -o-transition: all 0.5s ease; transition: all 0.5s ease; font-family: monospace; /* Always choose a nice font ;) */ } #wrapper.toggled { padding-bottom: 60px; /* Create a space for the footer at the bottom of the page */ } #footer-wrapper { z-index: 1000; position: fixed; bottom: 60px; /* Offset from bottom */ left: 0; width: 100%; height: 0px; /* Height for the footer */ margin-bottom: -60px; /* Initially hide the footer */ overflow: hidden; /* Just for the example */ background: #000; -webkit-transition: all 0.5s ease; -moz-transition: all 0.5s ease; -o-transition: all 0.5s ease; transition: all 0.5s ease; } #wrapper.toggled #footer-wrapper { height: 60px; /* when toggled, make the footer visible */ } #page-content-wrapper { width: 90%; position: relative; padding: 5%; } #wrapper.toggled #page-content-wrapper { position: relative; /* make relative to keep seeing the page content */ margin-top: -60px; /* Move content up by 60px*/ padding-top: 60px; /* Make sure no content is hidden from page*/ } /* Responsive Styles */ @media(min-width:768px) { #wrapper { padding-bottom: 0; } #wrapper.toggled { padding-bottom: 60px; } #footer-wrapper { height: 0px; } #wrapper.toggled #footer-wrapper { height: 60px; } #page-content-wrapper { padding: 20px; position: relative; } #wrapper.toggled #page-content-wrapper { position: relative; margin-top: 0; } } 
 <div id="wrapper"> <!-- Footer --> <div id="footer-wrapper"> <h1 style=" color: white; ">They see me going, they hatin'</h1> </div> <!-- /#footer-wrapper --> <!-- Page Content --> <div id="page-content-wrapper"> <div class="container-fluid"> <h2>Simple Footer</h1> <p>This template has a responsive menu toggling system. The menu will appear collapsed on smaller screens, and will appear non-collapsed on larger screens. When toggled using the button below, the menu will appear/disappear. On small screens, the page content will be pushed off canvas.</p> <p>Make sure to keep all page content within the <code>#page-content-wrapper</code>.</p> <a href="#menu-toggle" class="btn btn-secondary" id="menu-toggle">Toggle Menu</a> </div> </div> <!-- /#page-content-wrapper --> </div> 

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

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