Reputation: 187
I have a rather unique situation that seemingly works in all browsers except for Internet Explorer 11 it seems, so that is the primary use case that I am attempting to solve.
I am working on an idea for a website layout that involves utilizing display: flex;
on the <body>
to accommodate a variety of layout situations. Specifically, one involves having a "navbar" to the side and the site's content to the left. Using flex-grow: 1;
on the content allows me to fill the remaining space after the navbar, as well as automatically fill the full width of the browser window when I have to hide the navbar at a certain breakpoint.
However, if I add a max-width
to the content and attempt to center that within the remaining space using margin: 0 auto;
, it fails in Internet Explorer 11.
Here is a working example of this problem.
/* Code to Troubleshoot
// ----------------- */
body {
display: -webkit-flex;
display: flex;
}
nav {
-webkit-flex-basis: 160px;
flex-basis: 160px;
z-index: 2;
}
main {
-webkit-flex: 1;
flex: 1;
position: relative;
min-width: 1px;
max-width: 400px;
margin: 0 auto;
z-index: 1;
}
/* Presentational Styles
// ------------------ */
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: sans-serif;
font-weight: 300;
color: #bbb;
background-color: #eaeaea;
}
nav,
main {
height: 100vh;
background-color: #fff;
box-shadow: 0 0.15em 0.65em rgba(0, 0, 0, 0.15);
}
nav {
counter-reset: linkCount;
}
nav i {
display: block;
border-bottom: 1px solid #eaeaea;
padding: 0.925em 1em;
font-style: normal;
line-height: 1;
}
nav i:before {
counter-increment: linkCount;
content: "Link " counter(linkCount);
}
main:before {
content: "Main Content";
display: block;
position: absolute;
top: 50%;
left: 50%;
text-align: center;
-webkit-transform: translate3d(-50%, -50%, 0);
transform: translate3d(-50%, -50%, 0);
}
<nav>
<i></i>
<i></i>
<i></i>
</nav>
<main></main>
Ultimately, all of the following are what I'm working towards:
max-width
on the content area and center the content within the remaining space of the <body>
. Currently I am attempting to do this via margin: 0 auto;
on the content, which works in all browsers except Internet Explorer 11 it would seem (I have not yet tested on mobile, but all other desktop browsers seem to be in order).Upvotes: 4
Views: 9979
Reputation: 371003
In terms of flex layout, IE 11 is full of bugs. But there are usually ways around them.
In this case, just make these two adjustments to your main
element:
main {
flex: 1 1 auto; /* 1 */
position: relative;
min-width: 1px;
max-width: 400px;
margin: 0 auto;
z-index: 1;
width: 100%; /* 2 */
}
I based the adjustments on these two posts:
Upvotes: 8