Skip to content

Instantly share code, notes, and snippets.

Last active June 9, 2020 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rochellelewis/329eb28d9e8fffd5986eb3afec7ed9ac to your computer and use it in GitHub Desktop.
Save rochellelewis/329eb28d9e8fffd5986eb3afec7ed9ac to your computer and use it in GitHub Desktop.
React CSS Flexbox Sticky Footer

React Compatible Flexbox Sticky Footer


  1. Add CSS from index.css into your project's stylesheet
  2. In your app/public/index.html file, add class="sfooter" to <div id="root">
  3. In your src/index.js file, wrap all the markup that lives inside <BrowserRouter> and sits above your footer inside a <div class="sfooter-content"></div> (See lines 31, 39 in index.js)
* Flexbox Sticky Footer
* See line 33 in app/public/index.html
* See lines 31, 39 in index.js
/*corrects IE min-height bug*/
html { display: flex;}
body { width: 100%;}
.sfooter {
display: flex;
flex-direction: column;
min-height: 100vh;
.sfooter-content {
flex: 1 0 auto;
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
content="Web site created using create-react-app"
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
<title>React App</title>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" class="sfooter"></div>
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
import React from 'react';
import ReactDOM from 'react-dom'
import {BrowserRouter} from "react-router-dom";
import {Route, Switch} from "react-router";
import thunk from "redux-thunk";
import {applyMiddleware, createStore} from "redux";
import reducers from "./shared/reducers";
import {Provider} from "react-redux";
import 'bootstrap/dist/css/bootstrap.css';
import "./index.css";
import {NavBar} from "./shared/components/NavBar";
import {Footer} from "./shared/components/Footer";
import {Home} from "./pages/Home";
import {About} from "./pages/About";
import {Posts} from "./pages/posts/Posts";
import {FourOhFour} from "./pages/FourOhFour";
import {library} from "@fortawesome/fontawesome-svg-core";
import {far} from "@fortawesome/free-regular-svg-icons";
const store = createStore(reducers,applyMiddleware(thunk));
const Routing = (store) => (
<Provider store={store}>
{/* begin sticky footer wrapper */}
<div className="sfooter-content">
<Route exact path="/" component={Home}/>
<Route exact path="/about" component={About}/>
<Route exact path="/posts" component={Posts}/>
<Route component={FourOhFour}/>
</div>{/* close sticky footer wrapper */}
ReactDOM.render(Routing(store) , document.querySelector("#root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment