使用 css 让页脚占据底部空间
我希望我的页脚高度与剩余底部空间相同。目前我正在使用以下 css 作为页脚:
clear: both;
float: left;
background-color: #1F1102;
color: #E4F2FA;
min-height: 60px;
font-family: Verdana, Geneva, sans-serif;
font-size: 10px;
padding: 0;
padding-top: 10px;
text-align: left;
width: 100%;
min-width: 1000px;
margin: auto;
结果是:
这里你可以看到黑色有仅取最小高度。我希望它占据[标有问号]之后的整个剩余空间。我必须做出哪些改变才能得到这个?
注意:- 我不想给出 position:fixed
使其粘在底部。
I want my footer to take height same as the remaining bottom space. Currently I'm using following css for footer:
clear: both;
float: left;
background-color: #1F1102;
color: #E4F2FA;
min-height: 60px;
font-family: Verdana, Geneva, sans-serif;
font-size: 10px;
padding: 0;
padding-top: 10px;
text-align: left;
width: 100%;
min-width: 1000px;
margin: auto;
The result is:
Here as you can see the black has take only minimum height. I want it to take whole remaining space after it [that is marked with question marks]. Which changes do I have to make to get this?
note:- I don't want to give position:fixed
to make it stick to bottom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
嗯,简短的回答是,你不能!
更长的答案?你可以假装它。
为什么你不能?
因为块级元素无法拉伸和填充高度空间。
怎么造假呢?
使用与容器页脚相同的背景颜色(或相同的背景图像),这将导致它看起来它总是填满整个空间。
Well, the short answer is, You Can't!
The longer answer? You can fake it.
Why can't you?
Because a block level element is not able to strech and fill a space in height.
Fake it how?
Use the same background color as the footer for the container (or the same background image), that will cause it to appear like it's always fills up the entire space.
现在可以通过 Flexbox 使用类似于此处描述的方法 https ://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/。执行此操作,但将
flex-grow: 1
放在页脚元素而不是内容元素中(在文章中将其列为flex: 1
)。This is now possible with flexbox using a method similar to what is described here https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/. Do this, except put the
flex-grow: 1
in the footer element instead of the content element (in the article it's listed asflex: 1
).您实际上无法将块元素跨度设置为 CSS 中可用的完整高度。最好的方法是找到使用一些看起来相似的解决方法。
例如,您可以使用背景颜色(用于主体/包装)或位于底部的居中背景图像......
You don't really can make a block-element span to the full height available in CSS. Best way is find use some workaround, which looks alike.
For example you may use a background-color (for the body/wrapper) or a centered background-image positioned to the bottom…
这对我来说就像一个魅力(最初来自 how-to-keep-footer-at-bottom-of-page-with-css):
将其放入您的 css 中:
然后放入您的 index/master/_layout/whatever 中:
This worked like a charm for me (originally from how-to-keep-footer-at-bottom-of-page-with-css):
Put this in your css:
Then in your index/master/_layout/whatever:
我有同样类型的问题。对我有用的是在页脚中添加几个像素的填充,它最终占据了页面的底部。
这就是为我做的:
I had the same type of problem. What worked for me was to add a few pixels of padding to the footer and it ended up taking up the bottom of the page.
This is what did it for me: