简体   繁体   English

顺风响应断点的问题

[英]Trouble with responsive breakpoints in tailwind

I'm having trouble with the following simple html code using tailwindcss:我在使用 tailwindcss 处理以下简单的 html 代码时遇到问题:

<div class="md:hidden">
  default
</div>
<div class="hidden sm:visible md:hidden">
  sm
</div>
<div class="hidden md:visible lg:hidden">
  md
</div>
<div class="hidden lg:visible">
  lg
</div>

Instead of displaying "default" below 640px, then "sm" from 640px to 768px, then "md" from 768px to 1024px, then "lg" above 1024px, it seems to show "default" until 768px, then nothing.而不是在 640px 以下显示“默认”,然后从 640px 到 768px 显示“sm”,然后从 768px 到 1024px 显示“md”,然后在 1024px 以上显示“lg”,它似乎显示“默认”直到 768px,然后什么都没有。 I can't figure out why it doesn't seem to follow the guidelines in the docs .我不明白为什么它似乎不遵循文档中的指南 Codepen example here . Codepen 示例在这里

You need to use class block instead of hidden .您需要使用 class block而不是hidden You can also check here , I try to resolve your problem.您也可以在这里查看,我尝试解决您的问题。

The hidden class in tailwind changes the display property where the visible changes the visibility property. tailwind 中隐藏的 class 更改显示属性,其中可见更改可见性属性。 For you code to work you would need to use a display property such as flex.为了使代码正常工作,您需要使用显示属性,例如 flex。 More information can be found here Display Tailwind CSS Docs可以在此处找到更多信息Display Tailwind CSS Docs

Also to display default to 640px you need to change the first div to hidden after the small breakpoint instead of the medium breakpoint, change to class sm:hidden.另外要显示默认为 640px,您需要将第一个 div 更改为隐藏在小断点而不是中断点之后,更改为 class sm:hidden。 This will set display to hidden at 640px and higher.这会将显示设置为在 640px 及更高处隐藏。

See playground here在这里看游乐场

Updated Code:更新代码:

<div class="flex sm:hidden">default</div>
<div class="hidden sm:flex md:hidden">sm</div>
<div class="hidden md:flex lg:hidden">md</div>
<div class="hidden lg:flex">lg</div>

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

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