I want to embed the Monaco editor on a page under some fixed texts, I want the Monaco editor height to fill exactly the rest of the page. People gave me the answer here : JSBin :
<html> <style> html, body, .rb { margin: 0; height: 100%; } .rb { display: table; width: 100%; border-collapse: collapse; } .top, .myME { display: table-row; } .buffer { display: table-cell; } .top .buffer { background: lightblue; height:1%; } .myME .buffer { background: tomato; } #container { position:relative; } #container > * { overflow:auto; max-width:100%; max-height:100%; } </style> <body> <div class="rb"> <div class="top"> <div class="buffer"> 1<br/>2<br/>3<br/>4<br/> </div> </div> <div class="myME"> <div class="buffer" id="container"> </div> </div> </div> <script src="https://www.matrixlead.com/monaco-editor/min/vs/loader.js"></script> <script> require.config({ paths: { 'vs': 'https://www.matrixlead.com/monaco-editor/min/vs' }}) require(["vs/editor/editor.main"], function () { var editor = monaco.editor.create(document.getElementById('container'), { value: 'function x() {\n\tconsole.log("Hello world!");\n}', language: 'javascript', minimap: { enabled: false }, automaticLayout: true, scrollBeyondLastLine: false }); }); </script> </body> </html>
It works fine in Chrome, but it does not display the editor in Safari due to max-height:100% of #container > * . If we set it to max-height:100vh or height: 100vh , it works more or less in Safari (a little blinking when the focus reaches the bottom of the editor), while when scrolling up and down in Chrome, the scroller is displayed.
Does anyone have a solution that works in both Chrome and Safari? Otherwise, is it possible to set a specific rule only for Chrome or Safari?
css cross-browser height display monaco-editor
SoftTimur
source share