參考Bootstrap4官網例子Sticky footer,本文對其做了總結。
1、html標簽
將html顯示高度占滿(class="h-100")。
<html lang="en" class="h-100">
2、body標簽
設置body彈性布局,並將高度占滿(class="d-flex flex-column h-100")。
<body class="d-flex flex-column h-100">
3、main標簽
將main設置為不同的屏幕設備不設置收縮(role="main" class="flex-shrink-0")。
<main role="main" class="flex-shrink-0">
彈性收縮規則:
- flex-shrink-0 不同的屏幕設備不設置收縮
- flex-shrink-1 不同的屏幕設備設置收縮
4、footer標簽
設置footer頂部邊框高度自動設置(class="mt-auto")。
<footer class="footer mt-auto py-3">