tailwind css中的overflow hidden在动画中不起作用。

huangapple go评论70阅读模式
英文:

tailwind css overflow hidden doesn't working in animation

问题

我正在尝试通过移动到不同的位置来实现图像的动画效果,但每当它超出屏幕时,滚动条就会出现。我尝试在父元素中添加overflow: hidden,但没有起作用。以下是所需的代码片段。我正在使用带有Next.js的Tailwind CSS。

page.js:

<main className="flex min-h-screen items-center">
  <div className="container mx-auto flex">
    <div className="z-50 w-1/2">
      <h1 className="m-0 p-0 text-9xl">
        <span>{Title.slice(0, 2)}</span>
        <span className="text-secondary">{Title.slice(2)}</span>
      </h1>
    </div>
    <div className="w-/2">
      <Image
        className="absolute z-10 animate-leftToRight"
        src={whiteCircle}
        alt="white circle"
      />
    </div>
  </div>
</main>

tailwind.config.js:

theme: {
  extend: {
    colors: {
      primary: "#1c2340",
      secondary: "#f27eb2",
    },
    fontFamily: {
      Josefin: ["Josefin Sans", "sans-serif"],
      Poppins: ["Poppins", "sans-serif"],
    },
    animation: {
      leftToRight: "leftToRight 10s ease-in-out infinite",
    },
    keyframes: {
      leftToRight: {
        "0%, 100%": { left: "40%", top: "-20%", rotate: "0deg" },
        "50%": { left: "93%", top: "50%", rotate: "180deg" },
      },
    },
  },
},

layout.js:

<html lang="en">
  <body className="font-Poppins overflow-hidden max-w-[100vw] bg-primary text-white">
    <Navbar />
    <div className="mt-[60px]">{children}</div>
    <Footer />
  </body>
</html>

正如您在这张图片中所看到的,白色圆圈位于顶部,没有垂直滚动条。
tailwind css中的overflow hidden在动画中不起作用。

现在,一旦图像超出屏幕,滚动条就会出现。
tailwind css中的overflow hidden在动画中不起作用。

英文:

I'm trying to animate an image by moving to different positions. but whenever it goes beyond the screen. the scrollbar appears. I tried adding overflow hidden in the parent element but it didn't worked. here is the required code snippet. I'm using tailwind css with nextjs

page.js

&lt;main className=&quot;flex min-h-screen  items-center&quot;&gt;
      &lt;div className=&quot;container mx-auto flex&quot;&gt;
        &lt;div className=&quot;z-50 w-1/2&quot;&gt;
          &lt;h1 className=&quot;m-0 p-0 text-9xl&quot;&gt;
            &lt;span&gt;{Title.slice(0, 2)}&lt;/span&gt;
            &lt;span className=&quot;text-secondary&quot;&gt;{Title.slice(2)}&lt;/span&gt;
          &lt;/h1&gt;
        &lt;/div&gt;
        &lt;div className=&quot; w-/2&quot;&gt;
          &lt;Image
            className=&quot;absolute z-10 animate-leftToRight&quot;
            src={whiteCircle}
            alt=&quot;white circle&quot;
          /&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/main&gt;

tailwind.config.js

theme: {
    extend: {
      colors: {
        primary: &quot;#1c2340&quot;,
        secondary: &quot;#f27eb2&quot;,
      },
      fontFamily: {
        Josefin: [&quot;Josefin Sans&quot;, &quot;sans-serif&quot;],
        Poppins: [&quot;Poppins&quot;, &quot;sans-serif&quot;],
      },
      animation: {
        leftToRight: &quot;leftToRight 10s ease-in-out infinite&quot;,
      },
      keyframes: {
        leftToRight: {
          &quot;0%, 100%&quot;: { left: &quot;40%&quot;, top: &quot;-20%&quot;, rotate: &quot;0deg&quot; },
          &quot;50%&quot;: { left: &quot;93%&quot;, top: &quot;50%&quot;, rotate: &quot;180deg&quot; },
        },
      },
    },
  },

layout.js

&lt;html lang=&quot;en&quot;&gt;
      &lt;body className=&quot;font-Poppins overflow-hidden max-w-[100vw] bg-primary text-white&quot;&gt;
        &lt;Navbar /&gt;
        &lt;div className=&quot;mt-[60px]&quot;&gt;{children}&lt;/div&gt;
        &lt;Footer /&gt;
      &lt;/body&gt;
    &lt;/html&gt;

As you can see in this image that white circle is at top and there isn't vertical scroll
tailwind css中的overflow hidden在动画中不起作用。

now as soon as the image goes beyond the screen scroll appears

tailwind css中的overflow hidden在动画中不起作用。

答案1

得分: 0

你需要将 overflow-hidden 添加到堆叠上下文中。目前堆叠上下文是 html 元素,所以你可以在 globals.css 中添加如下代码:

html {
  @apply overflow-hidden;
}

或者你可以创建一个新的堆叠上下文,使用 relative 并将溢出隐藏添加到其中。

<main class="flex min-h-screen items-center relative overflow-hidden">

示例:https://play.tailwindcss.com/O8dHHydayG

英文:

You need to add overflow-hidden to the stacking context. At the moment that is the html element so you could add to globals.css:

html {
  @apply overflow-hidden;
}

Or you could create a new stacking context with relative and add the overflow hidden to that.

&lt;main class=&quot;flex min-h-screen items-center relative overflow-hidden&quot;&gt;

Exampe: https://play.tailwindcss.com/O8dHHydayG

huangapple
  • 本文由 发表于 2023年6月19日 01:01:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501671.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定