IE11 CSS display inline-block overflowing inside flexbox - html

I'm using an inline-block element with a large content inside a flex-box, and for some reason Internet Explorer 11 will not wrap the contents of this element, but push the flexbox out of the screen. It renders fine in Chrome and FireFox.
Example of my problem: https://codepen.io/anon/pen/YVboBX
<div class="page">
<main>
<radio-widget>
<layout-container>
<section class="icon">X</section>
<section class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in ipsum id lectus egestas scelerisque sit amet ut libero. Nam luctus turpis nisi, ut mollis libero sodales eu. Donec ante ante, venenatis non sodales sed, venenatis id lacus. In ante
risus, lobortis et ligula eget, commodo euismod risus. Ut sem orci, ultrices eu finibus vel, aliquam et quam. Nunc bibendum sodales libero et pulvinar. Cras porta feugiat lorem, vitae pretium augue fringilla et. Vestibulum dui lacus, ultrices
a ante et, euismod hendrerit ligula. Sed non urna ipsum. Fusce eget massa ex. Phasellus ac tempor ligula. Nullam sagittis dignissim ipsum, non commodo tellus luctus in. Etiam eget eleifend ex.
</section>
</layout-container>
</radio-widget>
</main>
<aside> a side</aside>
</div>
CSS
div.page {
display: flex;
flex-direction: row;
}
main {
flex-grow: 1;
flex-shrink: 1;
}
aside {
flex-grow: 0;
flex-shrink: 0;
flex-basis: 5em;
}
radio-widget {
display: inline-block;
}
layout-container {
display: flex;
}
section.icon {
flex-shrink: 0;
flex-grow:0;
flex-basis: 5em;
}
section.content {
flex-shrink: 1;
flex-grow:1;
}
I already tried the following (possible) fix, but that does not solve my issue:
IE CSS display: inline-block Rendering issue

In IE11, flex elements must have some sort of width defined. Add this to your code:
main {
flex-grow: 1;
flex-shrink: 1;
width: 100%; /* NEW */
}
radio-widget {
display: inline-block;
max-width: 100%; /* NEW */
}
revised demo
References:
Why IE11 doesn't wrap the text in flexbox?
CSS wrap text not working in IE

Related

Issue with "overflow: auto" on element inside fluid flexbox container in Internet Explorer 11

Task:
There is a box with fluid height that has to be centered in the browser window. It consists of three parts:
- top part with any length depending on text inside
- bottom part with any length depending on text indside
- middle part that is scrollable if there is not enough space to fit the text
Problem:
Implemeting the task I'm using flexbox on the parent display: flex; flex-direction: column;. Top and bottom parts are having flex-shrink: 0;
The part in the middle is set to overlow: auto. And for some reason there is no scroll in Internet Explorer 11. Overflow property is completely ignored. In Firefox and Chrome it works fine.
Screenshots:
Chrome/Firefox:
Internet explorer 11:
Code:
.wrapper {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
display: flex;
align-items: center;
justify-content: center;
}
.box {
display: flex;
flex-direction: column;
max-width: 300px;
max-height: 90vh;
width: 100%;
border: 1px solid red;
}
.top,
.bottom {
flex-shrink: 0;
padding: 10px;
background: #ccc;
}
.scrollable {
overflow: auto;
}
<div class="wrapper">
<div class="box">
<div class="top">I'm any length text</div>
<div class="scrollable">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eleifend nisi ac laoreet. Praesent commodo bibendum turpis nec finibus. Aenean ac tincidunt velit. Sed et sodales quam, efficitur viverra erat. Pellentesque aliquet ultrices lectus at vulputate. In pulvinar nec ex sed condimentum. Vivamus vitae vulputate urna. Aliquam lobortis iaculis lacus a dictum. Pellentesque odio mauris, tincidunt sit amet sem dapibus, pretium ornare turpis. In sit amet justo luctus, ultricies nisi eu, iaculis erat. Pellentesque et tempor nibh. Vivamus congue elementum elit, id tempus dolor laoreet sed.
Vestibulum dictum efficitur metus, in consectetur turpis. Vestibulum vel vehicula ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc congue, odio ac malesuada pharetra, velit nisl facilisis lorem, at tincidunt ex metus volutpat diam. Integer varius dolor at tellus dapibus ultrices. Nulla sagittis purus in mauris vestibulum, ac facilisis turpis condimentum. Ut mattis in ex eu mattis. Nullam ac elit metus. Nullam finibus tempus lacus, sit amet sagittis ante. Morbi sit amet sem a nisi volutpat luctus. Suspendisse eget condimentum dui. Proin suscipit sed sapien a efficitur.
</div>
<div class="bottom">I'm any length footer</div>
</div>
</div>
Is there any idea how to fix this issue? What's wrong there and how to make IE renders scroll?
IE has quite some bugs, and ignoring min/max-height is one of them.
In this case I found using flex column direction on the wrapper, and remove align-items: center does the trick.
To make it aligned horizontally centered, use auto margin on the box
Note, there is still one flaw with this in IE, if you start and manually change the browser height, the scroll won't disappear even if the text would fit, but if to reload the page, it works. Am still looking into this, to see what/if can be done to get rid of that issue.
Stack snippet
.wrapper {
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
display: flex;
flex-direction: column;
justify-content: center;
}
.box {
display: flex;
flex-direction: column;
max-width: 300px;
max-height: 90vh;
width: 100%;
border: 1px solid red;
margin: 0 auto;
}
.top,
.bottom {
flex-shrink: 0;
padding: 10px;
background: #ccc;
}
.scrollable {
overflow: auto;
}
<div class="wrapper">
<div class="box">
<div class="top">I'm any length text</div>
<div class="scrollable">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas lacinia eleifend nisi ac laoreet. Praesent commodo bibendum turpis nec finibus. Aenean ac tincidunt velit. Sed et sodales quam, efficitur viverra erat. Pellentesque aliquet ultrices lectus at vulputate. In pulvinar nec ex sed condimentum. Vivamus vitae vulputate urna. Aliquam lobortis iaculis lacus a dictum. Pellentesque odio mauris, tincidunt sit amet sem dapibus, pretium ornare turpis. In sit amet justo luctus, ultricies nisi eu, iaculis erat. Pellentesque et tempor nibh. Vivamus congue elementum elit, id tempus dolor laoreet sed.
</div>
<div class="bottom">I'm any length footer</div>
</div>
</div>
try using -ms-overflow-style: scrollbar; on the element

Why can a flex item take full height in a fixed-position flex container, unless the item has display: flex applied?

I have a markup like the following:
<div id="red">
<div id="yellow">
alot of text
</div>
</div>
<div id="blue">
</div>
I can't get yellow to take 100% of red's height, it only takes 100% of the window even if red is overflowing. It works if I set red's display to block, but I need flex...
#red {
position: fixed;
height: 100%;
overflow-y: scroll;
width: 100px;
background-color: red;
display: flex;
flex-direction: column;
align-items: stretch;
align-content: stretch;
}
#yellow {
display: flex;
flex-grow: 1;
background-color: yellow;
}
#blue {
background-color: blue;
}
Why not apply the overflow to yellow instead of red?
#red {
position: fixed;
height: 100vh;
width: 100px;
background-color: red;
display: flex;
flex-direction: column;
}
#yellow {
display: flex;
overflow-y: scroll;
background-color: yellow;
}
#blue {
background-color: blue;
}
body {
margin: 0;
}
<div id="red">
<div id="yellow">
Cras gravida, diam non adipiscing cursus, sapien urna adipiscing enim, at faucibus nunc felis at turpis. Aliquam erat volutpat. Nulla facilisi. Aenean nec nisi gravida ante convallis euismod sed quis odio. Sed nulla est, fringilla vel rhoncus vel, fermentum
et turpis. Curabitur eu posuere tortor. Integer sit amet nisl elit, gravida rutrum ipsum. Cras nisl est, sodales quis faucibus nec, tempus vel libero. Aliquam lobortis gravida erat, in placerat libero ultricies in. Curabitur volutpat lorem ut ligula
aliquet a fermentum augue porttitor. Vestibulum varius, purus id sollicitudin tincidunt, velit felis tincidunt erat, ut feugiat augue diam commodo lorem. Donec in augue non est tincidunt consequat. Mauris nec justo eget augue varius pulvinar id ut
risus. Donec fringilla, enim vitae tincidunt accumsan, urna elit laoreet tellus, ac gravida dolor dolor ac quam. Vestibulum dignissim felis quis tortor sollicitudin ut placerat mi adipiscing.
</div>
</div>
<div id="blue"></div>
Here's a link that may shed some light:
Make child element use 100% of total OVERFLOW height of parent
The yellow element actually takes 100% of your red element. The overflowing text does not cause your elements to change the size. You should remove height: 100% from #red and use min-height: 100% instead.

Text not wrapping in IE when container has flex-flow:column

I have the following code in my CSS:
#media screen and (max-width:600px) {
...
.container {
display: flex;
flex-flow: column;
max-width: 100%;
}
.container p {
display: block;
max-width: 100%;
}
...
}
This renders as expected in Chrome and Firefox, but in IE, the text fails to wrap, and each paragraph is rendered as a single line (which typically exceeds the width of the screen). There's a variety of solutions which address this situation when 'flex-flow' is not set to 'column'. Is there a way to fix the word-wrapping issue, under the condition that 'flex-flow' is set to 'column', and without setting a fixed width for either the container or child element?
Update:
The issue appears to pertain to the width of the element outside of the container. Here's a fiddle that illustrates what's going on.
HTML:
<div class='wrapper'>
<div class='container'>
<p>
Lorem ipsum...
</p>
<br>
<p>
Lorem ipsum dolor sit amet...
</p>
</div>
</div>
CSS:
.container {
display: flex;
flex-flow: column;
}
.container p {
max-width: 100%;
}
.wrapper {
clear: both;
float: left;
max-width: 1000px;
margin-top: 20px;
}
In the above example, the text will wrap in Chrome and Firefox, but will not wrap in IE. If, for example, the value of 'display' is changed to 'table', the paragraph text will wrap as expected in all browsers.
IE 10 and 11, which support flexbox, have many related bugs nonetheless.
In this particular case, IE is not recognizing the inherent width or display value of .container.
Here's a fix:
.wrapper {
clear: both;
float: left;
max-width: 1000px;
margin-top: 20px;
display: flex; /* NEW */
}
.container {
display: flex;
flex-flow: column;
width: 100%; /* NEW */
border: 1px solid red;
}
.container p {
max-width: 100%;
border: 1px dashed black;
}
<div class='wrapper'>
<div class='container'>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin hendrerit nulla id odio tincidunt, in rutrum diam dapibus. Mauris et urna luctus turpis sollicitudin dictum venenatis eget massa. Suspendisse maximus lectus in nunc placerat, nec interdum
massa iaculis. Nullam sit amet ex feugiat, cursus enim non, viverra lectus. Curabitur blandit risus sed dolor viverra, sit amet auctor metus ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus
placerat sollicitudin ligula, convallis mattis leo porttitor vitae. Praesent id metus id erat condimentum porta. Phasellus a sapien vel lacus imperdiet pellentesque sed at risus. Curabitur venenatis scelerisque augue, quis congue lorem feugiat eu.
Suspendisse placerat elit non augue suscipit pretium.
</p>
<br>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin hendrerit nulla id odio tincidunt, in rutrum diam dapibus. Mauris et urna luctus turpis sollicitudin dictum venenatis eget massa. Suspendisse maximus lectus in nunc placerat, nec interdum
massa iaculis. Nullam sit amet ex feugiat, cursus enim non, viverra lectus. Curabitur blandit risus sed dolor viverra, sit amet auctor metus ornare. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus
placerat sollicitudin ligula, convallis mattis leo porttitor vitae. Praesent id metus id erat condimentum porta. Phasellus a sapien vel lacus imperdiet pellentesque sed at risus. Curabitur venenatis scelerisque augue, quis congue lorem feugiat eu.
Suspendisse placerat elit non augue suscipit pretium.
</p>
</div>
</div>
jsFiddle
IE need the width to be set, and in your case on the wrapper.
Updated fiddle
.wrapper {
clear: both;
float: left;
width: 100%; /* added */
max-width: 1000px;
margin-top: 20px;
}

Why should I specify height: 0 even if I specified flex-basis: 0 in CSS3 flexbox?

I'm trying to make a fixed-size content reader with a title. The title should be shown even if the content scrolls. In this situation, I tried to make a structure like this using CSS3 flexbox:
.flex {
display: flex;
flex-direction: column;
width: 100%;
height: 150px;
border: 1px solid #ddd;
}
.title {
height: 50px;
line-height: 50px;
background: #eee;
}
.text-wrap {
flex: 1 0 0;
}
.text {
height: 100%;
overflow-y: auto;
}
<div class="flex">
<div class="title">Title</div>
<div class="text-wrap">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas faucibus justo vitae urna lacinia pharetra. Quisque nulla lorem, laoreet quis dapibus nec, vehicula vitae lorem. Nunc fringilla justo vel metus rhoncus, at congue leo dictum. Morbi congue tortor lacinia, mollis sapien indsadsadf, rutrum purus. Nam ornare dapibus mi, vitae varius diam tincidunt id. Donec maximus sem nec luctus euismod. Morbi a volutpat diam. In sapien orci, auctor et facilisis eu, finibus ac mauris. Vivamus eu nunc porta, congue libero quis, rutrum nibh. Proin feugiat vel augue mattis cursus.</p>
</div>
</div>
</div>
so that the content gets the rest of the height no matter what the flex container's size is. However, as you can see, the content gets out of the container and the overflow-y property is not working.
However, if I specify the height to 0 in the text-wrap, I can see that my code is working, as the following:
.flex {
display: flex;
flex-direction: column;
width: 100%;
height: 150px;
border: 1px solid #ddd;
}
.title {
height: 50px;
line-height: 50px;
background: #eee;
}
.text-wrap {
flex: 1 0 0;
height: 0;
}
.text {
height: 100%;
overflow-y: auto;
}
<div class="flex">
<div class="title">Title</div>
<div class="text-wrap">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas faucibus justo vitae urna lacinia pharetra. Quisque nulla lorem, laoreet quis dapibus nec, vehicula vitae lorem. Nunc fringilla justo vel metus rhoncus, at congue leo dictum. Morbi congue tortor lacinia, mollis sapien indsadsadf, rutrum purus. Nam ornare dapibus mi, vitae varius diam tincidunt id. Donec maximus sem nec luctus euismod. Morbi a volutpat diam. In sapien orci, auctor et facilisis eu, finibus ac mauris. Vivamus eu nunc porta, congue libero quis, rutrum nibh. Proin feugiat vel augue mattis cursus.</p>
</div>
</div>
</div>
I can't understand this behavior. I understand that flex-basis is a property which decides the initial height of the element (since the flex-direction is set to column), and that the flexbox divides the remaining heights to the elements according to the flex-grow property.
Then in this case, since the text-wrap's flex-basis(initial height) is set to 0 and it is the only element that has the property flex-grow, shouldn't the height be fixed to the rest of the flex container? Why is this behavior happening?
In addition, why should I specify the height: 0 property to the text-wrap in order to make my code work?
Thanks very much.
Your code is correct and working properly.
There is just one more flexbox feature you need to factor in:
An initial setting on a flex container is min-height: auto. This means that, by default, a flex item cannot be shorter than its content. Once you override this setting, your layout works as expected.
You could use height: 0, but here's the standard method:
.text-wrap {
flex: 1 0 0;
min-height: 0; /* new */
}
Full explanation here: Why doesn't flex item shrink past content size?
.flex {
display: flex;
flex-direction: column;
width: 100%;
height: 150px;
border: 1px solid #ddd;
}
.title {
height: 50px;
line-height: 50px;
background: #eee;
}
.text-wrap {
flex: 1 0 0;
min-height: 0; /* new */
}
.text {
height: 100%;
overflow-y: auto;
}
<div class="flex">
<div class="title">Title</div>
<div class="text-wrap">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas faucibus justo vitae urna lacinia pharetra. Quisque nulla lorem, laoreet quis dapibus nec, vehicula vitae lorem. Nunc fringilla justo vel metus rhoncus, at congue leo dictum. Morbi
congue tortor lacinia, mollis sapien indsadsadf, rutrum purus. Nam ornare dapibus mi, vitae varius diam tincidunt id. Donec maximus sem nec luctus euismod. Morbi a volutpat diam. In sapien orci, auctor et facilisis eu, finibus ac mauris. Vivamus
eu nunc porta, congue libero quis, rutrum nibh. Proin feugiat vel augue mattis cursus.</p>
</div>
</div>
</div>

How can I create a horizontally scrollable content with fixed width inside a nested flex container? [duplicate]

This question already has answers here:
Why don't flex items shrink past content size?
(5 answers)
Closed 5 years ago.
I have some content in a nested column whose parent is a nested flex container:
body,
html,
.container {
height: 100%;
}
body {
color: #fff;
}
.container {
display: flex;
overflow: hidden;
}
.sidebar {
width: 200px;
flex-shrink: 0;
background: red;
}
.main {
flex: 1;
display: flex;
}
.content {
flex: 1;
background: blue;
}
.scroll {
overflow-x: auto;
}
.overflowing {
width: 1024px;
}
.panel {
width: 100px;
flex-shrink: 0;
background: green;
}
<div class="container">
<div class="sidebar"></div>
<div class="main">
<div class="content">
<div class="scroll">
<div class="overflowing">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce non lorem blandit, aliquet augue in, egestas risus. Curabitur sit amet justo eget metus faucibus sodales. Vestibulum rhoncus vel libero id imperdiet. Quisque ante quam, tempus in metus a, aliquam sollicitudin tortor. Nam in sagittis nunc, et feugiat augue. Phasellus augue lacus, maximus et ipsum ac, placerat tincidunt risus. Curabitur velit diam, fermentum ac quam eget, ultricies elementum ipsum. Nullam justo dolor, consequat porttitor semper a, eleifend vitae ante. Phasellus egestas dolor sed erat dapibus, a scelerisque dui sagittis. Pellentesque eget venenatis nisi. Vestibulum neque nisl, cursus ut sagittis a, ultrices ac nunc. Etiam auctor nunc porta leo fermentum, a iaculis leo vestibulum. Donec lobortis, tellus a aliquet malesuada, ipsum elit sagittis lectus, sed mollis magna diam eu mauris. Vivamus semper nunc eget nunc lacinia pharetra.</div>
</div>
</div>
<div class="panel"></div>
</div>
</div>
The content has to be fixed-width (for whatever reason). On narrower viewports (like the one in the preview above) it's wider than its container, so I want it to scroll horizontally. I thought it would be as easy as wrapping it in a <div> with overflow-x: auto, but for some reason the content is pushing the right panel off-screen (you can see the panel if you view the result in full-screen).
This seems to happen only if the flex container is nested and the content's width is fixed. How can I prevent the panel from being pushed away?
Updated Answer
The original answer to this question is unnecessarily complex.
The simple truth is that flex items, by default, are min-width: auto. This means they cannot shrink below the size of their content.
That's why a horizontal scroll bar doesn't render in the blue text element. The content is unable to overflow because the item is always expanding to accommodate its content.
The solution is to override min-width: auto with min-width: 0.
.main {
min-width: 0; /* NEW */
}
.content {
min-width: 0; /* NEW */
}
jsFiddle demo
More details here: Why doesn't flex item shrink past content size?
Original Answer
The problem you're describing in your question doesn't exist in Chrome 47 or IE11. The code preview, whether small or full-screen, shows all three panels and horizontal scroll. It does what you want.
In Firefox and Chrome 48, however, there's clearly a problem. There's no horizontal scroll, and the right panel (green), is pushed off screen in the small preview.
These are bugs in Firefox and Chrome 48.
Here's the fix:
To enable a horizontal scrollbar in flexbox in FF/Chrome 48 add min-width: 0; to the parent(s) of the scrolling items.
(optional) To enable a vertical scrollbar add min-height: 0.
The above is a cross-browser solution; it doesn't appear to have any effect on non-buggy browsers. Hence, adding both min-width: 0 and min-height: 0 to your production code should be okay.
body,
html,
.container {
height: 100%;
}
body {
color: #fff;
}
.container {
display: flex;
overflow: hidden;
}
.sidebar {
width: 200px;
flex-shrink: 0;
background: red;
}
.main {
flex: 1;
display: flex;
min-width: 0; /* NEW */
}
.content {
flex: 1;
background: blue;
min-width: 0; /* NEW */
}
.scroll {
overflow-x: auto;
}
.overflowing {
width: 1024px;
}
.panel {
width: 100px;
flex-shrink: 0;
background: green;
}
<div class="container">
<div class="sidebar"></div>
<div class="main">
<div class="content">
<div class="scroll">
<div class="overflowing">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce non lorem blandit, aliquet augue in, egestas risus. Curabitur sit amet justo eget metus faucibus sodales. Vestibulum rhoncus vel libero id imperdiet. Quisque ante quam, tempus in metus a, aliquam sollicitudin tortor. Nam in sagittis nunc, et feugiat augue. Phasellus augue lacus, maximus et ipsum ac, placerat tincidunt risus. Curabitur velit diam, fermentum ac quam eget, ultricies elementum ipsum. Nullam justo dolor, consequat porttitor semper a, eleifend vitae ante. Phasellus egestas dolor sed erat dapibus, a scelerisque dui sagittis. Pellentesque eget venenatis nisi. Vestibulum neque nisl, cursus ut sagittis a, ultrices ac nunc. Etiam auctor nunc porta leo fermentum, a iaculis leo vestibulum. Donec lobortis, tellus a aliquet malesuada, ipsum elit sagittis lectus, sed mollis magna diam eu mauris. Vivamus semper nunc eget nunc lacinia pharetra.</div>
</div>
</div>
<div class="panel"></div>
</div>
</div>
Bug reports:
https://bugzilla.mozilla.org/show_bug.cgi?id=1043520
https://github.com/angular/material/issues/6841
https://code.google.com/p/chromium/issues/detail?id=580196