tailwind css - 无法让项目填写页面,总是卡在较小的容器中

Posted

技术标签:

【中文标题】tailwind css - 无法让项目填写页面,总是卡在较小的容器中【英文标题】:tailwind css - can't get item to fill out page, always stuck in smaller container 【发布时间】:2021-08-29 18:18:11 【问题描述】:

我正在尝试让我的页面看起来类似于 https://dash.blinq.app/onboarding/personal-details

目前使用此代码,我使用 tailwind 获得了非常糟糕的 flex 样式,我似乎无法弄清楚如何正确修复它。

    import  ChevronRightIcon, HomeIcon  from '@heroicons/react/solid'

const pages = [
   name: 'Privacy', href: '#', current: false ,
   name: 'Customizations', href: '#', current: true ,
   name: 'Details', href: '#', current: true ,


]

function BreadCrumbs() 
  return (
    <nav className="flex" aria-label="Breadcrumb">
      <ol className="flex items-center space-x-4">
        <li>
          <div>
            <a href="#" className="text-gray-400 hover:text-gray-500">
              <HomeIcon className="flex-shrink-0 h-5 w-5" aria-hidden="true" />
              <span className="sr-only">Home</span>
            </a>
          </div>
        </li>
        pages.map((page) => (
          <li key=page.name>
            <div className="flex items-center">
              <ChevronRightIcon className="flex-shrink-0 h-5 w-5 text-gray-400" aria-hidden="true" />
              <a
                href=page.href
                className="ml-4 text-sm font-medium text-gray-500 hover:text-gray-700"
                aria-current=page.current ? 'page' : undefined
              >
                page.name
              </a>
            </div>
          </li>
        ))
      </ol>
    </nav>
  )


  



export default function Example() 
    return (
      <div className="min-h-screen bg-white flex">
          <div className="hidden lg:block relative w-6/12 flex-auto">
          <img
            className="absolute inset-0 h-full   object-cover"
            src="https://images.unsplash.com/photo-1505904267569-f02eaeb45a4c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1908&q=80"
            
          />
        </div>
        <div className="flex-1 flex flex-col justify-center py-12 px-4 sm:px-6 lg:flex-none lg:px-20 xl:px-24">
        <BreadCrumbs/>

          <div className="mx-auto w-full max-w-lg lg:w-96">
            <div>
           
              <h2 className="mt-6 text-3xl font-extrabold text-gray-900">Welcome to Moodmap</h2>
              <p className="mt-2 text-sm text-gray-600">
              Let's get you started!

              
              </p>
            </div>
  
            <div className="mt-8">
             
  
              <div className="mt-6">
                <form action="#" method="POST" className="space-y-6">
                  <div>
                    <label htmlFor="email" className="block text-sm font-medium text-gray-700">
                      Email address
                    </label>
                    <div className="mt-1">
                      <input
                        id="email"
                        name="email"
                        type="email"
                        autoComplete="email"
                        required
                        className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
                      />
                    </div>
                  </div>
  
                  <div className="space-y-1">
                    <label htmlFor="password" className="block text-sm font-medium text-gray-700">
                      Password
                    </label>
                    <div className="mt-1">
                      <input
                        id="password"
                        name="password"
                        type="password"
                        autoComplete="current-password"
                        required
                        className="appearance-none block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm placeholder-gray-400 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
                      />
                    </div>
                  </div>
  
               
  
                  <div>
                    <button
                      type="submit"
                      className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
                    >
                      Next
                    </button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    )
  

看起来有点像这样。

我如何获得弹性以使表单正确适应?

谢谢!

【问题讨论】:

你能分享一个minimal reproducible example吗? 是的,我的意思是,上面的代码可以按原样呈现为页面 修复代码框以展示您的问题。现在我遇到了Internal Server Error @LeCoda 没有有效的沙盒链接,我们无法使用您的代码。如 aloisdg 所述,您的代码框链接会产生“内部服务器错误”。 【参考方案1】:

我猜你希望登录表单和面包屑占据更大的空间。

将图像从屏幕尺寸的一半缩小到 1/3 尺寸(移除 w-6/12 flex-auto)。

删除第二个 div 上的 lg:flex-none。

移除登录框的宽度限制(移除 max-w-lg lg:w-96 )

这应该让表单弯曲到剩余的 2/3 空间。

import  ChevronRightIcon, HomeIcon  from '@heroicons/react/solid'

const pages = [
   name: 'Privacy', href: '#', current: false ,
   name: 'Customizations', href: '#', current: true ,
   name: 'Details', href: '#', current: true ,


]

function BreadCrumbs() 
  return (
    <nav className="flex" aria-label="Breadcrumb">
      <ol className="flex items-center space-x-4">
        <li>
          <div>
            <a href="#" className="text-gray-400 hover:text-gray-500">
              <HomeIcon className="flex-shrink-0 w-5 h-5" aria-hidden="true" />
              <span className="sr-only">Home</span>
            </a>
          </div>
        </li>
        pages.map((page) => (
          <li key=page.name>
            <div className="flex items-center">
              <ChevronRightIcon className="flex-shrink-0 w-5 h-5 text-gray-400" aria-hidden="true" />
              <a
                href=page.href
                className="ml-4 text-sm font-medium text-gray-500 hover:text-gray-700"
                aria-current=page.current ? 'page' : undefined
              >
                page.name
              </a>
            </div>
          </li>
        ))
      </ol>
    </nav>
  )


  



export default function Example() 
    return (
      <div className="flex min-h-screen bg-white">
          <div className="relative w-4/12 lg:block">
          <img
            className="absolute inset-0 object-cover h-full"
            src="https://images.unsplash.com/photo-1505904267569-f02eaeb45a4c?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1908&q=80"
            
          />
        </div>
        <div className="flex flex-col justify-center flex-1 px-4 py-12 sm:px-6 lg:px-20 xl:px-24">
        <BreadCrumbs/>

          <div className="w-full ">
            <div>
           
              <h2 className="mt-6 text-3xl font-extrabold text-gray-900">Welcome to Moodmap</h2>
              <p className="mt-2 text-sm text-gray-600">
              Let's get you started!

              
              </p>
            </div>
  
            <div className="mt-8">
             
  
              <div className="mt-6">
                <form action="#" method="POST" className="space-y-6">
                  <div>
                    <label htmlFor="email" className="block text-sm font-medium text-gray-700">
                      Email address
                    </label>
                    <div className="mt-1">
                      <input
                        id="email"
                        name="email"
                        type="email"
                        autoComplete="email"
                        required
                        className="block w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm appearance-none focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
                      />
                    </div>
                  </div>
  
                  <div className="space-y-1">
                    <label htmlFor="password" className="block text-sm font-medium text-gray-700">
                      Password
                    </label>
                    <div className="mt-1">
                      <input
                        id="password"
                        name="password"
                        type="password"
                        autoComplete="current-password"
                        required
                        className="block w-full px-3 py-2 placeholder-gray-400 border border-gray-300 rounded-md shadow-sm appearance-none focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
                      />
                    </div>
                  </div>
  
               
  
                  <div>
                    <button
                      type="submit"
                      className="flex justify-center w-full px-4 py-2 text-sm font-medium text-white bg-indigo-600 border border-transparent rounded-md shadow-sm hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
                    >
                      Next
                    </button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
        
      </div>
    )
  

【讨论】:

以上是关于tailwind css - 无法让项目填写页面,总是卡在较小的容器中的主要内容,如果未能解决你的问题,请参考以下文章

CSS/Tailwind 让 flex-grow 孩子在溢出时滚动

React Tailwind - 无法运行 build.css 文件

将导航选项卡添加到 Tailwind CSS 导航栏

在 Tailwind 中扩展颜色

NextJS - 无法在 Tailwind CSS 中使用自定义颜色

使用 Tailwind 悬停时的 SVG 颜色填充