Why does Firefox cut off text in the flexbox layout, while Chrome does not? Is this a bug in Firefox?
I already know how to fix this bug so Firefox acts like Chrome: simply set .content
to flex: auto
, which implicitly sets flex-basis
to auto
instead of 0
. Alternatively, setting min-width: 0
or overflow-x: hidden
also works. But I want to know why.
I noticed that Firefox seems to use the really long <pre>
tag to set the width for the entire container div, while Chrome does not. But this only happens during flexbox. If there is no pre tag with long text in it, there is no bug.
Here's the Codepen. Resize it horizontally to see the difference between flexbox and not flexbox. I set a breakpoint to turn off flexbox when really narrow.
HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Cutoff example with Flexbox in Firefox</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css">
<link rel="stylesheet" type="text/css" href="recreate_bug.css" />
</head>
<body>
<div class="container container-main">
<div class="content">
<div class="container">
<!-- ---------------------------------------------------------------------- -->
<H1>Cutoff example with Flexbox in Firefox</H1>
<p>Hello, world! This is a message that will be cut-off due to the very long pre element underneath it. Just look at it. See? It is cutting off right here.</p>
<PRE>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</PRE>
<p class="flexbox">(Flexbox active)</p>
<!-- ---------------------------------------------------------------------- -->
</div> <!-- END .container -->
</div> <!-- END .content -->
</div> <!-- END .main -->
</body>
</html>
recreate_bug.css
:
body {
font-family: 'Source Sans Pro', Helvetica, Arial, sans-serif;
font-size: 22px;
color: #46545C;
}
h1 {
font-family: 'Ubuntu', 'Source Sans Pro', Helvetica, Arial, sans-serif;
font-size: 36px;
}
pre {
font-family: 'Source Code Pro', monospace;
font-size: .85em;
color: #EEEEEE;
background: #333333;
overflow: auto;
padding: 12px 18px;
}
.container {
margin: 0 auto;
padding: 0 18px;
}
.container-main {
overflow: hidden;
background: #b2a0e8;
}
.flexbox {
display: none;
}
/* Media Queries */
/* ---------------------------- */
/* Large Size */
@media screen and (min-width: 40em) {
.container-main {
display: flex;
background: #CADBD6;
}
.container {
margin: 0 50px;
}
.content {
flex: 1;
/* Comment out this width, and Chrome displays the same functionality */
width: 80%;
/* This width has the same effect */
/*width: calc(100% - 360px);*/
float: right;
}
.flexbox {
display: block;
}
}
Here is an image of what the cutoff looks like:
Thanks!