Flex-grow在Tailwind React中不起作用。

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

Flex-grow not working Tailwind React h-screen

问题

Here is the translated code portion you provided:

所以我有一个包含子组件的组件一开始它运行得很好但当组件不断增加时它不是将底部推开而是与底部组件重叠导致出现如下错误
[![在此输入图片描述][1]][1]

如您所见它堆叠在底部并重叠在其上....
这是我的尝试

<div className="m-2 flex-grow">
    <div className="flex flex-col md:flex-row md:justify-between">
        <div className="flex">
            <div
                name=" grey window"
                className="h-[130px] w-[130px] bg-[#d9d9d9]"
            ></div>
            <div name="text" className="md :flex md:flex-col md:pt-0">
                <div className="ml-2 text-left text-[#e44] md:text-xl text-base">
                    {props.props.sku_name}
                </div>
                <div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
                    {`Plant: ${props.props.plant}`}
                </div>
                <div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
                    {`SKU: ${props.props.sku}`}
                </div>{" "}
                <div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
                    {`Status: ${props.props.status}`}
                </div>
                <div className="md:text-l ml-2 text-left text-sm text-[#b4b4b4]">
                    {`Base Qty :${props.props.base_qty}, UOM: ${props.props.uom}`}
                </div>
            </div>
        </div>

        <div name="Buttons">
            <div className="mt-2 flex gap-4 md:mt-0 md:flex-col">
                <div className="rounded-md shadow">
                    <Button
                        variant="outlined"
                        size="medium"
                        color="error"
                        startIcon={<ContentCopyIcon />}
                        className="inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600  text-base font-medium text-white hover:bg-indigo-700 "
                    >
                        Copy
                    </Button>
                </div>
                <div className="rounded-md shadow">
                    <Button
                        variant="outlined"
                        size="medium"
                        startIcon={<ModeEditIcon />}
                        color="warning"
                        className="inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600  text-base font-medium text-white hover:bg-indigo-700"
                    >
                        Edit
                    </Button>
                </div>
            </div>
        </div>
    </div>
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <div>
        <p>dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh</p>
    </div>{" "}
    <

<details>
<summary>英文:</summary>

So i have an component with child inside the div component, it works fine at first but when the component keep increasing, instead of pushing the the footer the component overlapping the footer component causing an error like this:
[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/ju5eg.png

as you can see it stack infront of the footer and overlapping it....
here is my try:

    &lt;div className=&quot;m-2 flex-grow&quot;&gt;
          &lt;div className=&quot;flex flex-col md:flex-row md:justify-between&quot;&gt;
            &lt;div className=&quot;flex&quot;&gt;
              &lt;div
                name=&quot; grey window&quot;
                className=&quot;h-[130px] w-[130px] bg-[#d9d9d9]&quot;
              &gt;&lt;/div&gt;
              &lt;div name=&quot;text&quot; className=&quot;md :flex md:flex-col md:pt-0&quot;&gt;
                &lt;div className=&quot;ml-2 text-left text-[#e44] md:text-xl text-base&quot;&gt;
                  {props.props.sku_name}
                &lt;/div&gt;
                &lt;div className=&quot;md:text-l ml-2 text-left text-sm text-[#b4b4b4]&quot;&gt;
                  {`Plant: ${props.props.plant}`}
                &lt;/div&gt;
                &lt;div className=&quot;md:text-l ml-2 text-left text-sm text-[#b4b4b4]&quot;&gt;
                  {`SKU: ${props.props.sku}`}
                &lt;/div&gt;{&quot; &quot;}
                &lt;div className=&quot;md:text-l ml-2 text-left text-sm text-[#b4b4b4]&quot;&gt;
                  {`Status: ${props.props.status}`}
                &lt;/div&gt;
                &lt;div className=&quot;md:text-l ml-2 text-left text-sm text-[#b4b4b4]&quot;&gt;
                  {`Base Qty :${props.props.base_qty}, UOM: ${props.props.uom}`}
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
    
            &lt;div name=&quot;Buttons&quot;&gt;
              &lt;div className=&quot;mt-2 flex gap-4 md:mt-0 md:flex-col&quot;&gt;
                &lt;div className=&quot;rounded-md shadow&quot;&gt;
                  &lt;Button
                    variant=&quot;outlined&quot;
                    size=&quot;medium&quot;
                    color=&quot;error&quot;
                    startIcon={&lt;ContentCopyIcon /&gt;}
                    className=&quot;inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600  text-base font-medium text-white hover:bg-indigo-700 &quot;
                  &gt;
                    Copy
                  &lt;/Button&gt;
                &lt;/div&gt;
                &lt;div className=&quot;rounded-md shadow&quot;&gt;
                  &lt;Button
                    variant=&quot;outlined&quot;
                    size=&quot;medium&quot;
                    startIcon={&lt;ModeEditIcon /&gt;}
                    color=&quot;warning&quot;
                    className=&quot;inline-flex items-center justify-center rounded-md border border-transparent w-32 bg-indigo-600  text-base font-medium text-white hover:bg-indigo-700&quot;
                  &gt;
                    Edit
                  &lt;/Button&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;{&quot; &quot;}
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          &lt;div&gt;
            &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
          &lt;/div&gt;
          {/* &lt;div className=&quot;bg-white&quot;&gt;
            &lt;Box sx={{ width: &quot;100%&quot;, typography: &quot;body1&quot; }}&gt;
              &lt;TabContext
                TabIndicatorProps={{ style: { background: &quot;#FF0000&quot; } }}
                value={value}
                index={0}
                classes={{ root: useStyles.tab }}
              &gt;
                &lt;Box sx={{ borderColor: &quot;divider&quot;, p: 0 }}&gt;
                  &lt;TabList
                    index={0}
                    classes={{}}
                    onChange={handleChange}
                    variant=&quot;scrollable&quot;
                    scrollButtons=&quot;auto&quot;
                    aria-label=&quot;scrollable auto tabs example&quot;
                  &gt;
                    &lt;Tab label=&quot;BOM&quot; value=&quot;1&quot; /&gt;
                    &lt;Tab label=&quot;Calculation&quot; value=&quot;2&quot; /&gt;
                  &lt;/TabList&gt;
                &lt;/Box&gt;
                &lt;TabPanel style={{ padding: 2 }} value=&quot;1&quot;&gt;
                  Calculation
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;{&quot; &quot;}
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                    &lt;p&gt;dsajfkhjkfhkjasdhfkjahsdfkasjhdkfjashdkgdfgsfhdhh&lt;/p&gt;
                  &lt;/div&gt;
                &lt;/TabPanel&gt;
                &lt;TabPanel value=&quot;2&quot; style={{ padding: 2 }}&gt;
                  Calculation
                &lt;/TabPanel&gt;
              &lt;/TabContext&gt;
            &lt;/Box&gt;
          &lt;/div&gt; */}
        &lt;/div&gt;

and here is where i actually call the component to be used and display where there is data on it:

    &lt;div className=&quot; m-2 p-2 mr-2 bg-white h-screen &quot;&gt;
          &lt;div className=&quot;text-left pl-2 pb-4 font-bold text-3xl&quot;&gt;
            &lt;h2&gt;Find Material&lt;/h2&gt;
          &lt;/div&gt;
          &lt;div className=&quot;p-2 align-left&quot;&gt;
            &lt;form
              className=&quot;flex items-center&quot;
              onSubmit={(e) =&gt; {
                e.preventDefault();
                dataSKUList();
              }}
            &gt;
              &lt;Autocomplete
                isOptionEqualToValue={(option, value) =&gt;
                  option.value === value.value
                }
                style={{ width: &quot;100%&quot;, color: &quot;#ffffff&quot; }}
                onChange={(event, newValue) =&gt; {
                  handleSetSKU(newValue);
                }}
                id=&quot;grouped-demo&quot;
                options={options.sort(
                  (a, b) =&gt; -b.firstLetter.localeCompare(a.firstLetter)
                )}
                groupBy={(option) =&gt; option.firstLetter}
                getOptionLabel={(option) =&gt;
                  option.sku_name + `, code:(${option.sku})`
                }
                sx={{ width: 300 }}
                renderInput={(params) =&gt; {
                  params.inputProps.onKeyDown = handleKeyDown;
                  return &lt;TextField {...params} label=&quot;Search by SKU&quot; required /&gt;;
                }}
                renderGroup={(params) =&gt; (
                  &lt;ul key={params.key}&gt;
                    &lt;li&gt;
                      &lt;GroupHeader&gt;{params.group}&lt;/GroupHeader&gt;
                      &lt;GroupItems&gt;{params.children}&lt;/GroupItems&gt;
                    &lt;/li&gt;
                  &lt;/ul&gt;
                )}
              /&gt;
              &lt;div&gt;
                &lt;Button
                  type=&quot;submit&quot;
                  color=&quot;success&quot;
                  variant=&quot;contained&quot;
                  style={{
                    marginLeft: 10,
                    width: &quot;100%&quot;,
                    height: 54,
                  }}
                  startIcon={&lt;ContentPasteSearchIcon /&gt;}
                &gt;
                  Search
                &lt;/Button&gt;
              &lt;/div&gt;
            &lt;/form&gt;
          &lt;/div&gt;
          &lt;div className=&quot;bg-white scrollbar-hide&quot;&gt;
            {show ? (
              &lt;div className=&quot;h-full&quot;&gt;
                &lt;CardCalculation props={dataSpec} /&gt;
              &lt;/div&gt;
            ) : (
              &lt;&gt;&lt;/&gt;
            )}
          &lt;/div&gt;
        &lt;/div&gt;

can someone pointing out where it potentially be the error and any help on how to fix it?...
i think it will the `h-screen` that causing the problem....

</details>


# 答案1
**得分**: 1

使用 `flex-1` 而不是 `flex-grow`

尝试 [Tailwind-play](https://play.tailwindcss.com/ehESv4O6tb)。

我已经添加了页脚现在您不会看到任何溢出

<details>
<summary>英文:</summary>

Use `flex-1` instead of `flex-grow`

Try [Tailwind-play](https://play.tailwindcss.com/ehESv4O6tb)

I have added the footer, and now you dont see any overflow.



</details>



huangapple
  • 本文由 发表于 2023年1月6日 11:04:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026550.html
匿名

发表评论

匿名网友

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

确定