Laravel应用中Summernote工具栏遮挡textarea问题求助
Hey there, let's get that toolbar overlap sorted out—this is a common issue with Summernote, especially when using it inside modals or hidden containers. Here are the most likely fixes, tailored to your code snippet:
1. Initialize Summernote When the Modal is Shown
Your form is inside a modal (#editIssue) that's hidden on page load with display: none. Summernote can't calculate proper dimensions when it's initialized on a hidden element, which often leads to toolbar/textarea overlaps. Instead, initialize it after the modal is visible:
// Initialize Summernote when the modal opens $('#editIssue').on('shown.bs.modal', function() { // Replace #your-textarea-id with the actual ID of your textarea in the form $('#your-textarea-id').summernote({ height: 300, // Set a fixed height to avoid layout shifts toolbar: [ // Customize your toolbar buttons here if needed ['style', ['bold', 'italic', 'underline']], ['para', ['ul', 'ol', 'paragraph']], ['view', ['fullscreen']] ] }); }); // Clean up when the modal closes to prevent duplicate editors $('#editIssue').on('hidden.bs.modal', function() { $('#your-textarea-id').summernote('destroy'); });
2. Fix Z-Index & Positioning Conflicts
If the toolbar is still sitting on top of the editable area, add this CSS to your stylesheet to adjust stacking order:
/* Make sure the editor container has a proper stacking context */ .note-editor { position: relative; z-index: 10; } /* Ensure the toolbar stays above the editor content but not other page elements */ .note-toolbar { z-index: 11; }
Since your form is in a Bootstrap modal (which has a z-index of 1050), these values should keep Summernote's elements within the modal's context without overlapping.
3. Double-Check Your Initialization & Dependencies
Make sure you've included the required Summernote CSS and JS files in your layout (after Bootstrap, since Summernote relies on it):
<!-- Summernote CSS --> <link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet"> <!-- Summernote JS --> <script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>
Also, confirm you're initializing Summernote on the correct textarea ID—mixing up IDs is a common mistake!
4. Force Hide the Original Textarea
Summernote should automatically hide your original textarea once it initializes, but if custom CSS is overriding that, add this to ensure it's hidden:
#your-textarea-id { display: none !important; }
This prevents the original textarea from peeking through behind the toolbar.
The modal initialization fix (point 1) is probably the main culprit here—hidden containers throw off Summernote's dimension calculations. Give that a try first, and adjust the other steps if needed.
内容的提问来源于stack exchange,提问作者Peter

