我希望将 Monaco 编辑器嵌入到某个页面中一些固定的文本下方,并且想要使 Monaco 编辑器的高度正好填满剩余部分。有人在这里给出了答案:这里,同时提供了一个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>
在Chrome中完美运行,但由于# container > *
的max-height:100%
,在Safari中无法显示编辑器。如果我们将其设置为max-height:100vh
或height: 100vh
,则在Safari中运行得更好(当焦点到达编辑器底部时会有一点闪烁),而在Chrome中上下滚动时会显示一个滚动条。
是否有人有既适用于Chrome又适用于Safari的解决方案?否则,是否可能只为Chrome或Safari设置特定规则?
overflowingContentWidgets
是用来做什么的吗?如果我们隐藏它们,很容易就能让它正常工作。https://jsfiddle.net/pa8y2fzy/1/ - Jonathan