【问题标题】:w-screen and h-screen of tailwind are breaking the responsiveness顺风的w-screen和h-screen正在打破响应能力
【发布时间】:2021-05-13 06:13:29
【问题描述】:

我正在尝试使用 Nextjs 和 typescript 制作一个 404 页面。以下是截图:

如您所见,我在右侧和底部都有滚动条,它们破坏了响应能力。

我给了背景颜色以使其引人注目。

这是我的代码...

import Link from "next/link";
import { useRouter } from "next/router";
import React from "react";

interface Props {}

const ErrorPage: React.FC<Props> = ({}) => {
  const router = useRouter();
  return (
    <>
      <div className="bg-gray-900 h-screen w-screen flex justify-center items-center absolute z-0">
        <svg
          className="p-6 lg:p-48 fill-current text-gray-300"
          viewBox="0 0 445 202"
          xmlns="http://www.w3.org/2000/svg"
          fill="none"
          stroke="currentColor"
          // viewBox="0 0 24 24"
        >
          <path
            d="M137.587 154.953h-22.102V197h-37.6v-42.047H.53v-33.557L72.36 2.803h43.125V124.9h22.102v30.053zM77.886 124.9V40.537L28.966 124.9h48.92zm116.707-23.718c0 22.46 1.842 39.643 5.525 51.547 3.684 11.905 11.23 17.857 22.64 17.857 11.411 0 18.89-5.952 22.44-17.857 3.548-11.904 5.323-29.086 5.323-51.547 0-23.54-1.775-40.97-5.324-52.29s-11.028-16.98-22.438-16.98c-11.41 0-18.957 5.66-22.64 16.98-3.684 11.32-5.526 28.75-5.526 52.29zM222.759.242c24.887 0 42.339 8.76 52.356 26.28 10.018 17.52 15.027 42.406 15.027 74.66s-5.01 57.095-15.027 74.525c-10.017 17.43-27.47 26.145-52.356 26.145-24.887 0-42.339-8.715-52.357-26.145-10.017-17.43-15.026-42.271-15.026-74.525 0-32.254 5.009-57.14 15.026-74.66C180.42 9.001 197.872.241 222.76.241zm221.824 154.711h-22.102V197h-37.6v-42.047h-77.355v-33.557l71.83-118.593h43.125V124.9h22.102v30.053zM384.882 124.9V40.537l-48.92 84.363h48.92z"
            fillRule="nonzero"
          />
        </svg>
      </div>
      <div className="h-screen w-screen flex justify-center items-center relative z-10">
        <div className="p-6 text-center">
          <h2 className="uppercase text-xl lg:text-5xl font-black">
            We are sorry, Page not found!
          </h2>
          <p className="mt-3 uppercase text-sm lg:text-base font-semibold text-gray-900">
            The page you are looking for might have been removed had its name
            changed or is temporarily unavailable.
          </p>
          <div className="text-center">
            <Link href="/">
              <a
                className="mt-6 m-auto bg-primary text-white py-4 px-6 w-1/3 block rounded-full tracking-wide
                font-semibold font-display focus:outline-none focus:shadow-outline hover:bg-primaryAccent
                shadow-lg transition-css"
              >
                Back To Homepage
              </a>
            </Link>

            <button
              onClick={() => router.back()}
              className="mt-6 m-auto bg-primary text-white py-4 px-6 w-1/4 block rounded-full tracking-wide
                  font-semibold font-display focus:outline-none focus:shadow-outline hover:bg-primaryAccent
                  shadow-lg transition-css"
            >
              Go Back
            </button>
          </div>
        </div>
      </div>
    </>
  );
};

export default ErrorPage;

发生这种情况是因为 h-screen 和 w-screen 还是 flex 有问题?但是如果我不使用它们,我就不会像我期望的那样工作,它将一个 div 放在另一个 div 之上(绝对)。我可能看这段代码太久了,我迷失在太空中。 那么,我在这里做错了什么?谢谢。

【问题讨论】:

    标签: css flexbox next.js tailwind-css


    【解决方案1】:

    我建议有一个parent relative div

    <div class="h-screen w-screen relative">
    
        <!-- 404 -->
        <div class="bg-gray-900 flex justify-center items-center absolute inset-0 z-0"> // inset-0 is important
            <svg></svg>
        </div>
        
        <!-- content -->
        <div class="flex justify-center items-center absolute inset-0 z-10">
        </div>
    
    </div>
    

    【讨论】:

      【解决方案2】:

      我复制了你的设计。

      我建议将 h-screen 更改为 min-h-screen。

      您可以使用以下链接中的代码查看示例。

      https://play.tailwindcss.com/eD7VEDN5AR

      【讨论】:

      • 它适用于中小屏幕,但它仍然会破坏大屏幕和超大屏幕的响应能力
      • min-h-screen 添加到您的body 标签;这可能是问题所在。
      • 对不起,还是一样。 play.tailwindcss.com/l1uGRlqvGO
      猜你喜欢
      • 2020-05-16
      • 2021-05-03
      • 2020-08-02
      • 2021-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 2023-01-30
      相关资源
      最近更新 更多