卡片不具响应性

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

The cards are not responsive

问题

以下是您提供的代码的翻译部分:

function Team() {
  return (
    <div>
      <h1 className='text-center font-bold text-2xl'>Meet the Team</h1>
      <div className='p-3 m-3 flex space-x-10'>
      
        <div className="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
          <img className="rounded-t-lg" src="https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651" alt="" />
          <div className="p-5">
            <h5 className="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">Aadya Sharma </h5>
            <p className="mb-3 font-normal text-gray-700 dark:text-gray-400">Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.</p>
          </div>
        </div>
        
        <div className="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
          <img className="rounded-t-lg" src="https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651" alt="" />
          <div className="p-5">
            <h5 className="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">Shikhar Singh</h5>
            <p className="mb-3 font-normal text-gray-700 dark:text-gray-400">Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.</p>
          </div>
        </div>
        
        <div className="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700">
          <img className="rounded-t-lg" src="https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651" alt="" />
          <div className="p-5">
            <h5 className="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white">Hemant S. Rathod</h5>
            <p className="mb-3 font-normal text-gray-700 dark:text-gray-400">Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.</p>
          </div>
        </div>
      </div>
    </div>
  );
};

export default Team;

这是您提供的React代码,用于创建一系列卡片。如果您有其他问题或需要进一步的帮助,请随时告诉我。

英文:
function Team() {
  return (
    &lt;div&gt;
    &lt;h1 className=&#39;text-center font-bold	text-2xl&#39;&gt;Meet the Team&lt;/h1&gt;
    &lt;div className=&#39;p-3 m-3 flex space-x-10&#39;&gt;

      &lt;div className=&quot;max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700&quot;&gt;
        &lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
        &lt;div className=&quot;p-5&quot;&gt;
          &lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Aadya Sharma &lt;/h5&gt;
          &lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;



      &lt;div className=&quot;max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700&quot;&gt;
        &lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
        &lt;div className=&quot;p-5&quot;&gt;
          &lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Shikhar singh&lt;/h5&gt;
          &lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;


      &lt;div className=&quot;max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700&quot;&gt;
        &lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
        &lt;div className=&quot;p-5&quot;&gt;
          &lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Hemant S. Rathod&lt;/h5&gt;
          &lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    
    &lt;/div&gt;
  );
};

export default Team;

This is a code for a collections of card which are in rows at in desktop view but i want them to be in columns when it is phone view . i am using react with tailwind css.

答案1

得分: 1

Here's the translated content:

如果您希望在移动设备上将卡片放在单列,然后在较大设备上将其放在一行,有几种方法可以实现:flexbox 和 grid 可能是最简单的方式。

使用 flexbox 的一种方法是将 flex-direction 设置为 column(通过添加 flex-col 类),然后在某些较大的断点上更改方向为 row,并添加 flex-wrap。在 TailwindCSS 中,您使用断点(例如,sm、md、lg、xl、2xl),后跟冒号,然后是要在该断点应用的属性(例如,md:flex-row md:flex-wrap)。

使用 flexbox 的示例(运行并在全屏模式下测试响应性):

function Team() {
  return (
    <div>
      <h1 className="text-center text-2xl font-bold">Meet the Team</h1>
      <div className="flex flex-col gap-6 p-3 md:flex-row md:flex-wrap">
        <!-- Card 1 -->
        <!-- Card 2 -->
        <!-- Card 3 -->
      </div>
    </div>
  )
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Team />)

使用 grid 可以更好地控制在每个断点上显示的列数。例如,您可以在超小屏幕上使用 1 列,在小屏幕和中屏幕上使用 2 列,然后在大屏幕上使用 4 列。要实现这一点,您可以使用:grid grid-cols-1 gap-6 p-3 sm:grid-cols-2 lg:grid-cols-4

使用 grid 的示例:

function Team() {
  return (
    <div>
      <h1 className="text-center text-2xl font-bold">Meet the Team</h1>
      <div className="grid grid-cols-1 gap-6 p-3 sm:grid-cols-2 lg:grid-cols-4">
        <!-- Card 1 -->
        <!-- Card 2 -->
        <!-- Card 3 -->
      </div>
    </div>
  )
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Team />)

请注意,我仅提供了代码部分的翻译。

英文:

If you want the cards to be in a single column on mobile devices and then on larger devices to be in row, there are a couple of ways to do that: flexbox and grid are probably the easiest.

One way that you can use flexbox would be to set the flex-direction to column (by adding the class flex-col) and then for some larger breakpoint change the direction to row and add flex-wrap. In TailwindCSS you use the breakpoint (e.g., sm, md, lg, xl, 2xl) followed by a colon and then the property to apply at that breakpoint (e.g., md:flex-row md:flex-wrap).

Working snippet with flexbox (run and then open in full screen to test responsiveness):

<!-- begin snippet: js hide: true console: false babel: true -->

<!-- language: lang-js -->

function Team() {
return (
&lt;div&gt;
&lt;h1 className=&quot;text-center text-2xl font-bold&quot;&gt;Meet the Team&lt;/h1&gt;
&lt;div className=&quot;flex flex-col gap-6 p-3 md:flex-row md:flex-wrap&quot;&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Aadya Sharma&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Shikhar singh&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Hemant S. Rathod&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
)
}
const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));
root.render(&lt;Team/&gt;)

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

Grid would give you more control over the number of columns to display at each breakpoint. For example, you could have 1 column for extra small screens, 2 columns for small and medium screens and then on large screen have 4 columns. To do that you'd use: grid grid-cols-1 gap-6 p-3 sm:grid-cols-2 lg:grid-cols-4.

Working snippet with grid:

<!-- begin snippet: js hide: true console: false babel: true -->

<!-- language: lang-js -->

function Team() {
return (
&lt;div&gt;
&lt;h1 className=&quot;text-center text-2xl font-bold&quot;&gt;Meet the Team&lt;/h1&gt;
&lt;div className=&quot;grid grid-cols-1 gap-6 p-3 sm:grid-cols-2 lg:grid-cols-4&quot;&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Aadya Sharma&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Shikhar singh&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot; mx-auto max-w-sm rounded-lg border border-gray-200 bg-white shadow dark:border-gray-700 dark:bg-gray-800&quot;&gt;
&lt;img className=&quot;rounded-t-lg&quot; src=&quot;https://media.vanityfair.com/photos/6319eab06009e759e6638e28/master/w_2560%2Cc_limit/1421315651&quot; alt=&quot;&quot; /&gt;
&lt;div className=&quot;p-5&quot;&gt;
&lt;h5 className=&quot;mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white&quot;&gt;Hemant S. Rathod&lt;/h5&gt;
&lt;p className=&quot;mb-3 font-normal text-gray-700 dark:text-gray-400&quot;&gt;Here are the biggest enterprise technology acquisitions of 2021 so far, in reverse chronological order.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
)
}
const root = ReactDOM.createRoot(document.getElementById(&#39;root&#39;));
root.render(&lt;Team/&gt;)

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月20日 23:25:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75792182.html
匿名

发表评论

匿名网友

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

确定