'Make tailwindcss modal dialog with scrolling content?
Basing on tailwindcss 2 modal example https://alpinetoolbox.com/examples/modal I make modal dialog with header/footer/ Content with many rows. I try to set content with scrolling bar, like
<div style="height : calc( 100vh - 120 ) !important;" >
<div class="modal-header flex justify-between items-center pb-2">
...
</div>
<div class="modal-content py-4 text-left px-6 overflow-y-auto " style="height : calc( 100vh - 320 ) !important;">
But failed. Please take a look at codepen : https://codepen.io/sergeynilov/pen/vYyPrrE
MODIFIED BLOCK : I got scrolling as I need if to set in content block style definition.
<div class="modal-content py-4 text-left px-6" style="overflow-y: auto; max-height: 680px;">
Next I can make custom class (now it is not implemented yet) and put
overflow-y: auto; max-height: 680px
into it. And for any device I will make @media block with different height. That is the way I usually with with scss. But I suppose tailwindcss has better decision for it?
Thanks!
Solution 1:[1]
Had a similar question and found a solution here:
https://tailwind-elements.com/docs/standard/components/modal/#dialog_scrollable
I realize the question is old, just answering and linking the resource for the benefit of others.
EDIT: It took digging into their styles to get it working as a stand alone solution. Here it is:
<div class="z-40 fixed top-0 left-0 w-full h-full outline-none overflow-x-hidden overflow-y-auto"
id="exampleModalScrollable" tabindex="-1" aria-labelledby="exampleModalScrollableLabel" aria-hidden="true">
<div class="sm:h-[calc(100%-3rem)] max-w-lg my-6 mx-auto relative w-auto pointer-events-none">
<div
class="max-h-full overflow-hidden border-none shadow-lg relative flex flex-col w-full pointer-events-auto bg-white bg-clip-padding rounded-md outline-none text-current">
<div
class="flex flex-shrink-0 items-center justify-between p-4 border-b border-gray-200 rounded-t-md">
<h5 class="text-xl font-medium leading-normal text-gray-800" id="exampleModalScrollableLabel">
Modal title
</h5>
<button type="button"
class="btn-close box-content w-4 h-4 p-1 text-black border-none rounded-none opacity-50 focus:shadow-none focus:outline-none focus:opacity-100 hover:text-black hover:opacity-75 hover:no-underline"
data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="flex-auto overflow-y-auto relative p-4">
<p>This is some placeholder content to show the scrolling behavior for modals. We use repeated line breaks to demonstrate how content can exceed minimum inner height, thereby showing inner scrolling. When content becomes longer than the predefined max-height of modal, content will be cropped and scrollable within the modal.</p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>This content should appear at the bottom after you scroll.</p>
</div>
<div
class="flex flex-shrink-0 flex-wrap items-center justify-end p-4 border-t border-gray-200 rounded-b-md">
<button type="button"
class="inline-block px-6 py-2.5 bg-purple-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-purple-700 hover:shadow-lg focus:bg-purple-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-purple-800 active:shadow-lg transition duration-150 ease-in-out"
data-bs-dismiss="modal">
Close
</button>
<button type="button"
class="inline-block px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-blue-700 hover:shadow-lg focus:bg-blue-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-blue-800 active:shadow-lg transition duration-150 ease-in-out ml-1">
Save changes
</button>
</div>
</div>
</div>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |