大佬教程收集整理的这篇文章主要介绍了html – 当页面高度使用CSS动态更改时,将页脚保持在页面底部,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题是页面可以动态地改变它的高度.
使用the current solution I’m using,页脚位于页面底部.但是当页面高度动态变化时,页脚将保持在其确切位置.
页脚的CSS如下:
#footer { position: absolute; right: 0; bottom: 0; left: 0; }
html和body标签具有以下规则:
html,body { min-height: 100%; height: 100%; }
请参阅下面的代码段以获取可视化演示(最适合在全窗口模式下使用)
$(document).ready(function() { var button = $("#addContent"); var lorem = "<p>Proin cursus odio quis neque porttitor pretium. Duis cursus dolor mi,quis blandit eros Dictum vitae. Mauris tempus turpis non Leo commodo sagittis ac ac urna. Vivamus aliquet euismod posuere. Suspendisse at semper mauris. Phasellus blandit convallis Tincidunt. Maecenas elementum ullamcorper risus,a vestibulum ex accumsan sed. Nulla facilisi.</p><p>Proin cursus odio quis neque porttitor pretium. Duis cursus dolor mi,a vestibulum ex accumsan sed. Nulla facilisi.</p>"; button.click(function() { $("main button").before(lorem); }); });
* { box-sizing: border-box; } body { margin: 0; } header { BACkground: #333; color: #fff; padding: 25px; } main { padding: 25px; } main h3 { margin-top: 0; } code { BACkground: #f1f1f1; padding: 0 5px; } footer { position: absolute; BACkground: #ededed; padding: 25px; color: #000; right: 0; bottom: 0; left: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <header> <p>Just a sample header</p> </header> <main> <h3>Some sample content</h3> <p>Click on the <code>button</code> to see what i mean.</p> <p>When the <code>heigth</code> of the page dynamically changes,the <code>footer</code> will stay at its exact position.</p> <button id="addContent">Click to add more content</button> </main> <footer> <p>The footer</p> </footer>
如何让CSS知道高度变化?并将该页脚保留在文档的底部而不是它停留在窗口的底部?
但绝对定位的元素已从文档流中完全删除,因此在这种情况下它将与其他元素重叠,但如果我们添加变换,我们可以解决:translateY(100%)
所以最后你会得到:
body { margin: 0; position: relative; } footer { position: absolute; BACkground: #ededed; padding: 25px; color: #000; right: 0; bottom: 0; left: 0; transform: translateY(100%); }
以上是大佬教程为你收集整理的html – 当页面高度使用CSS动态更改时,将页脚保持在页面底部全部内容,希望文章能够帮你解决html – 当页面高度使用CSS动态更改时,将页脚保持在页面底部所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。