最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Quill: How to prevent toolbar from scrolling and set the height? - Stack Overflow

programmeradmin3浏览0评论

I am trying to follow the sample at but have problems setting the height of the editor box and preventing the toolbar from scrolling off-screen.

My code is:

<div id="editorcontainer" style="height:10em; min-height:100%; overflow-y:auto;">
   <div id="editor" name="editor" style="min-height:100%; height:auto;"></div>
</div>

<script>
  var quill = new Quill("#editor",{
     modules: {
       toolbar: [ ... ]
         },
         scrollingContainer: "#editorcontainer",
         theme: "snow"
     });
</script>

The JS Filddle is available at /

The output looks like this:

There are two problems:

  1. The tool bar is not fixed and scrolls.
  2. The vertical scrollbar has a scrollable region all the time, even when the editor is empty.

How do I solve these two problems?

I am trying to follow the sample at https://quilljs.com/playground/#autogrow-height but have problems setting the height of the editor box and preventing the toolbar from scrolling off-screen.

My code is:

<div id="editorcontainer" style="height:10em; min-height:100%; overflow-y:auto;">
   <div id="editor" name="editor" style="min-height:100%; height:auto;"></div>
</div>

<script>
  var quill = new Quill("#editor",{
     modules: {
       toolbar: [ ... ]
         },
         scrollingContainer: "#editorcontainer",
         theme: "snow"
     });
</script>

The JS Filddle is available at https://jsfiddle.net/OldGeezer/xpvt214o/556844/

The output looks like this:

There are two problems:

  1. The tool bar is not fixed and scrolls.
  2. The vertical scrollbar has a scrollable region all the time, even when the editor is empty.

How do I solve these two problems?

Share Improve this question edited Aug 7, 2018 at 2:12 u936293 asked Aug 6, 2018 at 11:08 u936293u936293 16.2k34 gold badges121 silver badges219 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 14

I had to modify two of quill's classes to get what I wanted. Like so

.ql-container.ql-snow {
    height: auto;
}
.ql-editor {
    height: 150px;
    overflow-y: scroll;
}

My solution was to add an additional encapsulating div with position:relative to establish the reference frame for ql-toolbar which is set to position:absolute.

The editorcontainer is then given a margin-top:3em to hold the toolbar (when it is short enough to fill a single row).

<div style="position:relative;margin-top:5em;">
  <div id="editorcontainer" style="height:10em; min-height:100%; 
         overflow-y:auto;margin-top:3em">
     <div id="editor" style="min-height:100%; height:auto;"></div>
  </div>
</div>

<style>
  .ql-toolbar { position: absolute; top: 0;left:0;right:0}
</style>

The working fiddle is at https://jsfiddle.net/OldGeezer/oLq2bnzv/

You will need to modify one of quill's class

.ql-container.ql-snow {
  border: none;
  height: 150px;
  overflow: scroll;
}

For those who suffered from Angular quill in this question,

I suggest you should add this code in the style.css.

.ql-toolbar {
  position: sticky;
}

.ql-container {
  overflow-x:auto;
  height: 300px; /* whatever you what */
}
  1. The tool bar is not fixed and scrolls.

You can change the CSS of the toolbar like the following:

.ql-toolbar {
    position: fixed;
    top: 0;
}
  1. The vertical scrollbar has a scrollable region all the time, even when the editor is empty.

You can lower the min-height of the editor so it's lower than the container (80% for example).

发布评论

评论列表(0)

  1. 暂无评论