Codemirror: Incorrect height when inside a flexbox container

Created on 2 Dec 2015  路  4Comments  路  Source: codemirror/CodeMirror

The .CodeMirror-scroll element has the wrong height when the editor is inside a flexbox container. I've tested in Firefox and Chrome (Ubuntu 15.10), but the problem only occurs in Chrome. This may need to be reported as a browser bug instead. Here is a test case:

<!DOCTYPE html>
<html>
<head>
    <style>
        html, body{ height:100%; }
        body{
            margin:0;
            display:flex;
            flex-direction:column;
        }
        .CodeMirror{
            margin:10px;
            border:1px solid black;
            flex-grow:1;
        }
    </style>
    <link rel="stylesheet" href="lib/codemirror.css">
    <script src="lib/codemirror.js"></script>
</head>
<body>
    <script> CodeMirror(document.body, {lineNumbers: true}); </script>
</body>
</html>

Most helpful comment

Just spent a couple of hours trying to fix it. In case it helps anyone, one way is to set parent as position=absolute and height=100%. And then apply display=flex and position=relative to grandparent.

All 4 comments

This is a Chrome bug. See also #3231. If you want to spend energy on creating a minimal (without CodeMirror) reproducing page and reporting it to the Chrome people, that'd be awesome (the bug is that height: 100% doesn't use the parent's height, even if that is position: relative, when that parent is in a flex container).

Closing since there doesn't seem to be a known workaround that CodeMirror could apply (if you find one, do comment).

Just spent a couple of hours trying to fix it. In case it helps anyone, one way is to set parent as position=absolute and height=100%. And then apply display=flex and position=relative to grandparent.

Just spent a couple of hours trying to fix it. In case it helps anyone, one way is to set parent as position=absolute and height=100%. And then apply display=flex and position=relative to grandparent.

U just saved me bruh!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JosephPecoraro picture JosephPecoraro  路  3Comments

mtaran-google picture mtaran-google  路  5Comments

droidenator picture droidenator  路  3Comments

liviuignat picture liviuignat  路  3Comments

hameddhib-dydu picture hameddhib-dydu  路  5Comments