简体   繁体   English

2 col 布局扩展超过最大宽度(TAILWIND CSS)

[英]2 col layout expanding past max width (TAILWIND CSS)

Here's a quick rundown of the relevant code before I ask this question在我问这个问题之前,这是相关代码的快速概述

The HomePage component主页组件

const Home = () => {
  return (
    <div>
      <div>
        {questions.map((question) => (
          <div key={question.id} className="mb-4">
            <Question
              title={question.title}
              contentPreview={question.contentPreview}
            />
          </div>
        ))}
      </div>
      <Card className="p-4">Side Controlls</Card>
    </div>
  );
};

The Question component问题组件

const Question = ({ title, contentPreview }) => (
  <Card className="p-4 break-words">
    <h1 className="mb-4 text-lg text-blue-600">{title}</h1>
    <p className="text-gray-500">{contentPreview}</p>
    <div className="flex mt-4 gap-4">
      <InfoIcon
        icon={<HeartIcon />}
        info={20}
        iconClassName="text-red-400 w-6 h-6"
        infoClassName="text-gray-500"
      />
      <InfoIcon
        icon={<CommentIcon />}
        info={40}
        iconClassName="text-blue-400 w-6 h-6"
        infoClassName="text-gray-500"
      />
    </div>
  </Card>
);

The Layout component that HomePage is being wrapped in包含 HomePage 的 Layout 组件

const Layout = ({ children }) => (
  <div className="bg-gray-100">
    <div className="flex flex-col min-h-screen">
      <NavBar />
      <div className="mt-4 max-w-7xl self-center w-full px-4">{children}</div>
    </div>
  </div>
);

And here are some screenshots of whats happening这是一些正在发生的事情的屏幕截图

A screenshot with the containing div of the HomePage Component having a background so you can see better where it is https://gyazo.com/b8aa356912f973f854299c665c66de76带有背景的 HomePage 组件的包含 div 的屏幕截图,因此您可以更好地看到它在哪里https://gyazo.com/b8aa356912f973f854299c665c66de76

A screenshot with the div that containing all the questions colored is the reddish color and the (soon to be) controls/sidebar colored in green https://gyazo.com/2ceb6a1277f1de4506531a2bcf0b9b17包含所有颜色问题的 div 的屏幕截图是红色,(即将)控件/侧边栏以绿色https://gyazo.com/2ceb6a1277f1de4506531a2bcf0b9b17

And finally, the real problem is this screenshot, because I want both the controls and List of questions to be side by side my first instinct is to give the containing div of both of them a class of "flex" but when I do that this happens https://gyazo.com/af6206b95dc684bbcb316a8d33362b62 and the controls get push beyond the "limits" to the right.最后,真正的问题是这个截图,因为我希望控件和问题列表并排,我的第一反应是给它们两个包含的 div 一个“flex”的 class 但是当我这样做时发生https://gyazo.com/af6206b95dc684bbcb316a8d33362b62并且控件超出了右侧的“限制”。 if anyone knows or has any ideas about why this might be happening please let me know.如果有人知道或对为什么会发生这种情况有任何想法,请告诉我。 thank you谢谢你

(PS. please do not answer and say "use bootstrap" or use "x ui framework instead" because I'm using tailwind and do want to stay in tailwind) (PS。请不要回答说“使用引导程序”或使用“x ui 框架”,因为我正在使用顺风并且确实想留在顺风中)

I want both the controls and List of questions to be side by side我希望控件和问题列表并排

In such case, use flex flex-1 on both the sections to have even width .在这种情况下,请在两个部分上使用flex flex-1以获得均匀的宽度 Else, you can still specify a width like question section flex w-8/12 and the side controls section flex w-4/12 .否则,您仍然可以指定宽度,例如问题部分flex w-8/12和侧面控制部分flex w-4/12

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

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