【发布时间】:2018-01-19 09:47:54
【问题描述】:
我想在某些固定文本下的页面中嵌入 Monaco Editor,我希望 Monaco Editor 的高度恰好填满页面的其余部分。人家给了我答案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>
它在 Chrome 中完美运行,但由于 max-height:100% 的 #container > *,它不会在 Safari 中显示编辑器。如果我们将它设置为max-height:100vh 或height: 100vh,它在 Safari 中或多或少可以工作(当焦点到达编辑器底部时会有点闪烁),而在 Chrome 中上下滚动时会显示一个滚动条。
有没有人可以在 Chrome 和 Safari 中使用的解决方案?否则,是否可以只为 Chrome 或 Safari 设置特定规则?
【问题讨论】:
标签: css cross-browser height display monaco-editor