前言

这个保持在底部,想一想以前怎么实现的。今日早读文章由@Stephanie Eckles分享,@飘飘翻译。

正文从这开始~~

This is the first post in a series examining modern CSS solutions to problems I’ve been solving over the last 13+ years of being a frontend developer.

这是一系列研究现代 CSS 解决方案的第一篇文章,我在过去13年多的时间里一直致力于前端开发。

For many years, I constantly referred to this article by Matthew James Taylor for a method to keep a webpage footer at the bottom of the page regardless of the main content length. This method relied on setting an explicit footer height, which is not scalable but a very good solution BF (Before Flexbox).

多年来,我一直参考Matthew James Taylor的这篇文章,想找到一种方法,在不考虑内容长度的情况下,让网页页脚保持在页面的底部。这种方法依赖于设置一个明确的页脚高度,在Flexbox之前这是一个不可伸缩的,非常好的解决方案。

If you mostly deal with SPA development, you may be confused about why this problem is still around, but it’s still a possibility to find your footer floating up for:

如果您主要处理SPA开发,你可能会困惑为什么这个问题仍然存在,但是仍然有可能发现你的页脚漂浮起来:

login pages

blog/news articles (with no ads…)

nterstitial pages of a flow like confirming actions

product listing pages

calendar event details

登录页面

博客/新闻文章(无广告…)

流程的插页式页面,例如确认动作

产品列表页

日历活动详细信息

There are two ways to handle this with modern CSS: flexbox and grid.

使用现代CSS有两种方法来处理这个问题:flexbox和grid。

Here’s the demo, defaulted to the flexbox method. If you open the full Codepen, you can swap the $method variable to grid to view that alternative.

这是演示,默认为flexbox方法。如果你打开Codepen,你可以将$method变量换成grid来查看这个备选方案。

Read on past the demo to learn about each method.

通过阅读演示来了解每种方法。

  1. Hello World

  2. Marzipan soufflé cotton candy tart sweet bonbon. Macaroon fruitcake pie gummies gummi bears biscuit dragée. Topping icing marshmallow. Soufflé gummies dessert jelly dessert liquorice.