How to get tables to grow infinitely off screen side by side instead of top and bottom with html and css

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

How to get tables to grow infinitely off screen side by side instead of top and bottom with html and css

问题

我正在遍历用户对象,并希望使用 overflowX: "scroll" 让表格并排显示。

问题:

当我遍历表格时,它们只能以垂直堆叠的方式显示,而不是并排显示(请注意)。我希望表格在屏幕右侧显示,即第二个表格应该显示在屏幕右侧。

Code Sandbox链接

<div
  style={{ display: &quot;block&quot;, overflowX: &quot;scroll&quot;, overflowY: &quot;visible&quot; }}
>
  {wrestlersGrades.length
    ? wrestlersGrades.map((wrestler) => {
        return (
          <table>
            <thead>
              <tr>
                <WrestlerTableHeader wrestler={wrestler} />
              </tr>
            </thead>
            <tbody className=" ">
              {/*<WrestlerTableBody wrestler={wrestler} />*/}
              <tr>
                <td>Alfreds Futterkiste</td>
                <td>Maria Anders</td>
                <td>Germany</td>
                <td>Alfreds Futterkiste</td>
                <td>Maria Anders</td>
                <td>Germany</td>
                <td>Alfreds Futterkiste</td>
                <td>Maria Anders</td>
                <td>Germany</td>
              </tr>
              <tr>
                <td>Centro comercial Moctezuma</td>
                <td>Francisco Chang</td>
                <td>Mexico</td>
                <td>Centro comercial Moctezuma</td>
                <td>Francisco Chang</td>
                <td>Mexico</td>
                <td>Centro comercial Moctezuma</td>
                <td>Francisco Chang</td>
                <td>Mexico</td>
              </tr>
              <tr>
                <td>This is America</td>
                <td>Hello </td>
                <td>United States of America</td>
                <td>This is America</td>
                <td>Hello </td>
                <td>United States of America</td>
                <td>This is America</td>
                <td>Hello </td>
                <td>United States of America</td>
              </tr>
            </tbody>
          </table>
        );
      })
    : null}
</div>
英文:

I am mapping through user object and want tables to display side by side using overflowX: &quot;scroll&quot;

The Problem:

When I am mapping through the tables I am only able to get them to display one on top of the other and not side by side (Please note) I want the tables to display off screen. Meaning the second table should display to the right off the screen.

Code Sandbox link

  &lt;div
        style={{ display: &quot;block&quot;, overflowX: &quot;scroll&quot;, overflowY: &quot;visible&quot; }}
      &gt;
  {wrestlersGrades.length
          ? wrestlersGrades.map((wrestler) =&gt; {
              return (
                &lt;table&gt;
                  &lt;thead&gt;
                    &lt;tr&gt;
                      &lt;WrestlerTableHeader wrestler={wrestler} /&gt;
                    &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody className=&quot;&quot;&gt;
                    {/*&lt;WrestlerTableBody wrestler={wrestler} /&gt;*/}
                    &lt;tr&gt;
                      &lt;td&gt;Alfreds Futterkiste&lt;/td&gt;
                      &lt;td&gt;Maria Anders&lt;/td&gt;
                      &lt;td&gt;Germany&lt;/td&gt;
                      &lt;td&gt;Alfreds Futterkiste&lt;/td&gt;
                      &lt;td&gt;Maria Anders&lt;/td&gt;
                      &lt;td&gt;Germany&lt;/td&gt;
                      &lt;td&gt;Alfreds Futterkiste&lt;/td&gt;
                      &lt;td&gt;Maria Anders&lt;/td&gt;
                      &lt;td&gt;Germany&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td&gt;Centro comercial Moctezuma&lt;/td&gt;
                      &lt;td&gt;Francisco Chang&lt;/td&gt;
                      &lt;td&gt;Mexico&lt;/td&gt;
                      &lt;td&gt;Centro comercial Moctezuma&lt;/td&gt;
                      &lt;td&gt;Francisco Chang&lt;/td&gt;
                      &lt;td&gt;Mexico&lt;/td&gt;
                      &lt;td&gt;Centro comercial Moctezuma&lt;/td&gt;
                      &lt;td&gt;Francisco Chang&lt;/td&gt;
                      &lt;td&gt;Mexico&lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;tr&gt;
                      &lt;td&gt;This is America&lt;/td&gt;
                      &lt;td&gt;Hello &lt;/td&gt;
                      &lt;td&gt;United States of America&lt;/td&gt;
                      &lt;td&gt;This is America&lt;/td&gt;
                      &lt;td&gt;Hello &lt;/td&gt;
                      &lt;td&gt;United States of America&lt;/td&gt;
                      &lt;td&gt;This is America&lt;/td&gt;
                      &lt;td&gt;Hello &lt;/td&gt;
                      &lt;td&gt;United States of America&lt;/td&gt;
                    &lt;/tr&gt;
                  &lt;/tbody&gt;
                &lt;/table&gt;
              );
            })
          : null}
&lt;/div&gt;
 

答案1

得分: 1

使用flex属性的最简单解决方案:代码沙盒

英文:

The easiest solution with flex: Code sandbox

huangapple
  • 本文由 发表于 2023年2月10日 06:00:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404876.html
匿名

发表评论

匿名网友

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

确定