I'm using flexbox to make my footer stick to the bottom, and for the most part it's working. My problem is, I need the content to be within a specified width, that I set with max-width
and center with margin-left:auto;
and margin-right:auto;
. When I activate flexbox, the contents are squished by the margin-left
and margin-right
rules, and do not take up the space defined by max-width
. I would like to know why this is happening and how to get my footer to look how I want it to look.
Here is how I want my footer to look:
And here is how flexbox is affecting it:
body {
display: flex;
flex-direction: column;
min-height: 100%;
}
div#content {
flex: 1 0 auto;
}
footer {
flex: 0 0 auto;
max-width: 67.5rem;
margin-left: auto;
margin-right: auto;
padding-left: 1.25rem;
padding-right: 1.25rem;
padding-bottom: 1.875rem;
padding-top: 3.5rem;
}
<body>
<header>...</header>
<div id="content">...</div>
<footer>
<span id="left">left text</span>
<span id="mid">right text url@mail</span>
<span id="icons">...</span>
</footer>
</body>
If I change max-width
to width
then it works, but then when I test it in my browser using the device-mobile setting to see how it would look on a mobile device, the width
property makes the footer too big and messes up the content. If I take out the margin-left
and margin-right
properties, then my footer looks like this:
As you can see it's no longer centered. I can't use the flex-basis
property because that only affects the height of the footer. Please help.
Edit
Here is a snippet with margin-left
and margin-right
taken out and replaced with display:flex;
and justify-content:space-around;
. Be sure to click "Full page" to view with a larger viewport.
body {
display: flex;
flex-direction: column;
min-height: 100%;
}
div#content {
flex: 1 0 auto;
}
footer {
flex: 0 0 auto;
max-width: 67.5rem;
padding-left: 1.25rem;
padding-right: 1.25rem;
padding-bottom: 1.875rem;
padding-top: 3.5rem;
display: flex;
justify-content: space-around;
}
<body>
<header>...</header>
<div id="content">...</div>
<footer>
<span id="left">left text</span>
<span id="mid">right text url@mail</span>
<span id="icons">...</span>
</footer>
</body>