我希望在页面底部添加一行“保留所有权利...” 。我尝试使用绝对定位,但是当窗口调整为较小的高度时,它的效果不如预期。
我该如何实现这个简单的目标?
你可能希望将绝对定位的div放在相对定位的容器中 - 这样它仍会被包含在容器中而不是浏览器窗口中。
<div style="position: relative;background-color: blue; width: 600px; height: 800px;">
<div style="position: absolute; bottom: 5px; background-color: green">
TEST (C) 2010
</div>
</div>
尝试:
.bottom {
position: fixed;
bottom: 0;
}
试一试这个
<head>
<style type ="text/css" >
.footer{
position: fixed;
text-align: center;
bottom: 0px;
width: 100%;
}
</style>
</head>
<body>
<div class="footer">All Rights Reserved</div>
</body>
根据我的研究和开始这篇文章,我认为这是最佳选择:
<p style=" position: absolute; bottom: 0; left: 0; width: 100%; text-align: center;">This will stick at the botton no matter what :).</p>
这个选项允许调整页面大小,即使页面是空白的,它也会保持在底部。
#copyright {
float: left;
padding-bottom: 10px;
padding-top: 10px;
text-align: center;
bottom: 0px;
width: 100%;
}
<div id="copyright">
Copyright 2018 © Steven Clough
</div>
<style>
#container {
position: relative;
height: 100%;
}
#footer {
position: absolute;
bottom: 0;
}
</style>
</HEAD>
<BODY>
<div id="container">
<h1>Some heading</h1>
<p>Some text you have</p>
<br>
<br>
<div id="footer"><p>Rights reserved</p></div>
</div>
</BODY>
</HTML>
关键在于使用<br>
来换行。因此,当页面很小的时候,您会看到页脚位于页面底部,就像您想要的那样。
但是,当页面很大以至于您必须向下滚动时,您的页脚将会在整个上方内容的下面两行。如果您随后再扩大页面,您的页脚将始终向下移动。我希望有人会发现这个有用。