简体   繁体   English

使用 Tailwindcss 启用滚动

[英]Enabling scroll using Tailwindcss

I am using Tailwindcss and trying to achieve a design, in which there is a scroller in middle section.我正在使用 Tailwindcss 并试图实现一个设计,其中中间部分有一个滚动条。

在此处输入图像描述

However, the scroller is disabled and it's full height is not fit to it's parent.但是,滚动条被禁用,它的全高不适合它的父级。

Following is the part of the code:以下是部分代码:

<div class="h-full bg-green-200">
                <div class="overflow-y-scroll">
                  <p class="my-10">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex
                    eius fugit optio sapiente provident enim nihil at nemo
                    molestiae quo, inventore consectetur esse nisi, consequuntur
                    consequatur! Dolor facilis quasi molestiae?
                  </p>
                  <p class="my-10">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex
                    eius fugit optio sapiente provident enim nihil at nemo
                    molestiae quo, inventore consectetur esse nisi, consequuntur
                    consequatur! Dolor facilis quasi molestiae?
                  </p>
                  <p class="my-10">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex
                    eius fugit optio sapiente provident enim nihil at nemo
                    molestiae quo, inventore consectetur esse nisi, consequuntur
                    consequatur! Dolor facilis quasi molestiae?
                  </p>
                  
                </div>
              </div>

I tried giving h-full, h-fit.我试着给 h-full,h-fit。 I also tried using grow, flex-1.我也尝试过使用grow,flex-1。 But it isn't working as expected.但它没有按预期工作。

Full code here in sandbox:沙盒中的完整代码:

https://codesandbox.io/s/spring-sun-e9mrrv https://codesandbox.io/s/spring-sun-e9mrrv

h-full : sets an element's height to 100% of its parent, as long as the parent has a defined height. h-full :只要父元素具有定义的高度,就将元素的高度设置为其父元素的 100%。

you have set the overflow as hidden to the parent element.您已将溢出设置为隐藏到父元素。 So basically your div has full height as its content but the overflow is hidden.所以基本上你的 div 有完整的高度作为它的内容,但是溢出是隐藏的。

You have also set overflow of your div to scroll but since its fitting its content wholly in the div, the scrollbar is disabled as there is nothing to scroll.您还设置了 div 的溢出以滚动,但由于它的内容完全适合 div,因此滚动条被禁用,因为没有可滚动的内容。

You can either set a fixed height to the div where you need the scroll or some of the parent divs.您可以为需要滚动的 div 或某些父 div 设置固定高度。 Check out the solution here在这里查看解决方案

Change your改变你的
overflow-y-scroll溢出-y-滚动
To
overflow-y-auto溢出-y-自动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM