gpt4 book ai didi

javascript - 使 QuillJS 编辑器高度 100%

转载 作者:行者123 更新时间:2023-11-29 10:56:55 26 4
gpt4 key购买 nike

在下面的应用程序中,我希望 Quill 编辑器填充页眉和页脚中的现有空间。我尝试将其设置为 100%,但这会向整个页面添加一个滚动条。如何让Quill在填充空间的同时适配屏幕尺寸。 (如果降低高度编辑器高度应该降低)

var quill = new Quill('#editor', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
});
html,body {
margin: 0;
height: 100%;
}

#container {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}

#header {
height: 40px;
background: red;
}

#footer {
height: 40px;
background: red;
}

#editor-container {
height: 100%;
}

#editor {
height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.6/quill.snow.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.6/quill.js"></script>
<div id="container">
<div id="header">Header</div>
<div id="editor-container">
<div id="editor">Sample</div>
</div>
<div id="footer">Footer</div>
</div>

最佳答案

问题是 height: 100% 来自 ql-container 类导致溢出。您可以尝试以下操作:

  1. flex: 1 添加到 #editor-container 并使它也成为一个column flexbox

    <
  2. flex: 1width: 100% 添加到 #editor 并且对于大内容添加 overflow-y : 自动

请看下面的演示:

var quill = new Quill('#editor', {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
['bold', 'italic', 'underline'],
['image', 'code-block']
]
},
placeholder: 'Compose an epic...',
theme: 'snow' // or 'bubble'
});
html,body {
margin: 0;
height: 100%;
}

* {
box-sizing: border-box;
}

#container {
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}

#header {
height: 40px;
background: red;
}

#footer {
height: 40px;
background: red;
}

#editor-container {
height: 100%;
/* added these styles */
flex: 1;
display: flex;
flex-direction: column;
}

#editor {
height: 100%;
/* added these styles */
flex: 1;
overflow-y: auto;
width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.6/quill.snow.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/quill/1.3.6/quill.js"></script>
<div id="container">
<div id="header">Header</div>
<div id="editor-container">
<div id="editor">Sample</div>
</div>
<div id="footer">Footer</div>
</div>

关于javascript - 使 QuillJS 编辑器高度 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55264524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com