【问题标题】:How to use repeat and minmax in tailwindHow to use repeat and minmax in tailwind
【发布时间】:2022-12-27 13:12:57
【问题描述】:

Hello I have a question how can I use repeat and minmax in grid in tailwind. I did something like this and it did not work.

const DetailedAssetCard = () => {
  return (
    <div className=" bg-gray-100 rounded-lg grid  grid-cols-[repeat(4, minmax(100px, 500px))]  ">
      <div className="w-32 h-32 rounded-full ">
        <Image src={Btc} alt="" />
      </div>

      <p>
        Hello <span className="block ">123</span>
      </p>
      <p>
        Hello <span className="block ">123</span>
      </p>
      <p>
        Hello <span className="block ">123</span>
      </p>
      <p>
        Hello <span className="block ">123</span>
      </p>
      <p>
        Hello <span className="block ">123</span>
      </p>
      <p>
        Hello <span className="block ">123</span>
      </p>
    </div>
  );
};

【问题讨论】:

    标签: reactjs tailwind-css


    【解决方案1】:

    By default, Tailwind includes grid-template-column utilities for creating basic grids with up to 12 equal width columns. You can customize these values by editing theme.gridTemplateColumns or theme.extend.gridTemplateColumns in your tailwind.config.js file.

    So your tailwind config file should look like this

    module.exports = {
      theme: {
        extend: {
         gridTemplateColumns: {
            // added new 4 column grid as new4
            'new4': 'repeat(4, minmax(100px, 500px))'
            }
        },
      },
      plugins: [],
    }
    
    

    And use like this grid-cols-new4.

    const DetailedAssetCard = () => {
      return (
        <div className=" bg-gray-100 rounded-lg grid  grid-cols-new4  ">
          <div className="w-32 h-32 rounded-full ">
            <Image src={Btc} alt="" />
          </div>
    
          <p>
            Hello <span className="block ">123</span>
          </p>
          .
          .
          .
          <p>
            Hello <span className="block ">123</span>
          </p>
        </div>
      );
    };
    

    A nice example I have created here to understand more .

    【讨论】:

      【解决方案2】:

      Remove any spaces inside grid-cols-[repeat(4,minmax(100px,500px))]

      const DetailedAssetCard = () => { return (

        <p>
          Hello <span className="block ">123</span>
        </p>
        <p>
          Hello <span className="block ">123</span>
        </p>
        <p>
          Hello <span className="block ">123</span>
        </p>
        <p>
          Hello <span className="block ">123</span>
        </p>
        <p>
          Hello <span className="block ">123</span>
        </p>
        <p>
          Hello <span className="block ">123</span>
        </p>
      </div>
      

      ); };

      【讨论】:

        猜你喜欢
        • 2022-12-02
        • 2022-12-28
        • 2022-12-27
        • 2022-12-02
        • 1970-01-01
        • 2022-12-02
        • 2022-12-02
        • 2022-12-01
        • 2022-12-27
        相关资源
        最近更新 更多