<Tab>元素居中MaterialUI组件。

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

center materialUI element <Tab>

问题

我想要的是**应该覆盖整个页面宽度,其中的**元素应该均匀地使用50%的宽度

我尝试了以下方式:

<Tabs
  sx={{ paddingBottom: 5, width: "100%", display: "flex", justifyContent: "space-around" }}
>
  <Tab style={{ width: "50%" }} label="Search Movies" />
  <Tab style={{ width: "50%" }} label="Search TV Series" />
</Tabs>

但这不起作用。

英文:

what i want is that the < Tabs > should cover the whole page width and the < Tab > element inside it should use 50% of the width equally

i tried doing

&lt;Tabs
  sx={{ paddingBottom: 5 ,width:&quot;100%&quot;,display:&quot;flex&quot;,justifyContent:&quot;space-around&quot;}} 
  &gt;
   &lt;Tab style={{ width: &quot;50%&quot; }} label=&quot;Search Movies&quot; /&gt;
   &lt;Tab style={{ width: &quot;50%&quot; }} label=&quot;Search TV Series&quot; /&gt;
&lt;/Tabs&gt;

but this is not working

答案1

得分: -1

为了使Tabs组件覆盖整个页面宽度,并使内部元素均匀使用50%的宽度,您可以尝试以下方法:

<Tabs
  sx={{ paddingBottom: 5, width: "100%", display: "flex", justifyContent: "center" }}
  centered
>
  <Tab label="Search Movies" style={{ flex: "0 0 50%" }} />
  <Tab label="Search TV Series" style={{ flex: "0 0 50%" }} />
</Tabs>

解释:

  1. 将父Tabs组件的width属性设置为"100%",以使其覆盖整个页面宽度。
  2. 在父Tabs组件上使用display: "flex"justifyContent: "center",以水平居中Tabs元素。
  3. 在Tabs组件上添加centered属性,以均匀分布Tabs元素在可用空间中。
  4. 在每个Tab组件上设置style属性为flex: "0 0 50%",以使它们均匀占用50%的可用宽度。

通过应用这些更改,Tabs组件应该覆盖整个页面宽度,每个Tab元素将均匀占用50%的宽度。

英文:

To make the Tabs component cover the whole page width and have the elements inside use 50% of the width equally, you can try the following approach:

&lt;Tabs
  sx={{ paddingBottom: 5, width: &quot;100%&quot;, display: &quot;flex&quot;, justifyContent: &quot;center&quot; }}
  centered
&gt;
  &lt;Tab label=&quot;Search Movies&quot; style={{ flex: &quot;0 0 50%&quot; }} /&gt;
  &lt;Tab label=&quot;Search TV Series&quot; style={{ flex: &quot;0 0 50%&quot; }} /&gt;
&lt;/Tabs&gt;

Explanation:

  1. Set the width property of the parent Tabs component to &quot;100%&quot; to make it cover the full page width.
  2. Use display: &quot;flex&quot; and justifyContent: &quot;center&quot; on the parent Tabs component to horizontally center the Tabs elements.
  3. Add the centered prop to the Tabs component to evenly distribute the Tabs elements across the available space.
  4. Set the style property on each Tab component with flex: &quot;0 0 50%&quot; to make them occupy 50% of the available width equally.

By applying these changes, the Tabs component should span the entire page width, and the Tab elements will each take up 50% of the width evenly.

huangapple
  • 本文由 发表于 2023年7月3日 16:02:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602878.html
匿名

发表评论

匿名网友

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

确定