๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

์‚ฝ์งˆ๊ธฐ๋ก

[์‚ฝ์งˆ๊ธฐ๋ก] Tailwind์—์„œ w-1/3๊ณผ w-[33%]๋Š” ์™œ ๋‹ค๋ฅผ๊นŒ?

728x90
๋ฐ˜์‘ํ˜•

๐Ÿšจ ๋ฌธ์ œ ์ƒํ™ฉ

ํ…Œ์ด๋ธ” ์ปฌ๋Ÿผ์„ ๋น„์œจ ๋‹จ์œ„(ex. w-1/16)๋กœ ์„ค์ •ํ–ˆ์„ ๋•Œ, ์ „์ฒด ์ปฌ๋Ÿผ์˜ ํ•ฉ์ด 1์ด์ง€๋งŒ ๊ฐ€๋กœ ์Šคํฌ๋กค์ด ์ƒ๊ธฐ๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ–ˆ๋‹ค.

<thead className="bg-white text-gray-500">
  <tr>
    <th className="w-1/16 px-4 py-2 whitespace-nowrap">๋ฆฌ๋ทฐ ๋ฒˆํ˜ธ</th>
    <th className="w-4/16 px-4 py-2 whitespace-nowrap">์ฒดํ—˜ํ•™์Šต๋ช…</th>
    <th className="w-2/16 px-4 py-2 whitespace-nowrap">์ž‘์„ฑ์ž</th>
    <th
      className="w-2/16 px-4 py-2 cursor-pointer select-none whitespace-nowrap"
      onClick={() => onSort("rating")}
    >
      ํ‰์  <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="rating" disabled={sortedReviews.length === 0} />
    </th>
    <th className="w-5/16 px-4 py-2">๋ฆฌ๋ทฐ ๋‚ด์šฉ</th>
    <th
      className="w-1/16 px-4 py-2 cursor-pointer select-none whitespace-nowrap"
      onClick={() => onSort("date")}
    >
      ์ž‘์„ฑ์ผ <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="date" disabled={sortedReviews.length === 0} />
    </th>
    <th
      className="w-1/16 px-4 py-2 cursor-pointer select-none whitespace-nowrap text-center"
      onClick={() => onSort("reply")}
    >
      ๋‹ต๋ณ€ ์—ฌ๋ถ€ <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="reply" disabled={sortedReviews.length === 0} />
    </th>
  </tr>
</thead>

๐Ÿค” ์›์ธ

Tailwind์˜ fraction ๋‹จ์œ„(w-1/3, w-1/16 ๋“ฑ)๋Š” ๋นŒ๋“œ ์‹œ์ ์— ๊ณ ์ •๋œ ์†Œ์ˆ˜์  ๊ณ„์‚ฐ๊ฐ’์œผ๋กœ ๋ณ€ํ™˜๋œ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด w-1/16์€ ์‹ค์ œ๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด CSS๋กœ ๋ฐ”๋€๋‹ค.

.w-1\/16 { 
    width: 6.25%; 
}
 
 

ํ•˜์ง€๋งŒ ์ด๋Ÿฐ ์ˆ˜์น˜๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ํ•ฉ์น˜๋ฉด 6.25 × 16 = 100.000000... ์ฒ˜๋Ÿผ ์†Œ์ˆ˜์  ๋ฐ˜์˜ฌ๋ฆผ ์˜ค์ฐจ๊ฐ€ ๋ˆ„์ ๋œ๋‹ค.
table-fixed๋Š” ๊ฐ ์…€์˜ ํญ์„ ๊ฐ•์ œ๋กœ ํ•ฉ์‚ฐํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์ด ์˜ค์ฐจ๊ฐ€ ํ•ฉ์ณ์ง€๋ฉด ์ „์ฒด ํญ์ด 100%๋ฅผ ์ดˆ๊ณผํ•˜๋ฉด์„œ overflow๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
๊ทธ ๊ฒฐ๊ณผ, ๋ธŒ๋ผ์šฐ์ €๋Š” ๊ฐ€๋กœ ์Šคํฌ๋กค์„ ์ƒ์„ฑํ•œ๋‹ค.


๐Ÿ› ๏ธ ํ•ด๊ฒฐ ๊ณผ์ •

fraction ๋Œ€์‹  ๋ช…์‹œ์ ์ธ % ๋‹จ์œ„๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

<thead className="bg-white text-gray-500">
  <tr>
    <th className="w-[7%] px-4 py-2 whitespace-nowrap">๋ฆฌ๋ทฐ ๋ฒˆํ˜ธ</th>
    <th className="w-[24%] px-4 py-2 whitespace-nowrap">์ฒดํ—˜ํ•™์Šต๋ช…</th>
    <th className="w-[12%] px-4 py-2 whitespace-nowrap">์ž‘์„ฑ์ž</th>
    <th
      className="w-[12%] px-4 py-2 cursor-pointer select-none whitespace-nowrap"
      onClick={() => onSort("rating")}
    >
      ํ‰์  <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="rating" disabled={sortedReviews.length === 0} />
    </th>
    <th className="w-[26%] px-4 py-2">๋ฆฌ๋ทฐ ๋‚ด์šฉ</th>
    <th
      className="w-[10%] px-4 py-2 cursor-pointer select-none whitespace-nowrap"
      onClick={() => onSort("date")}
    >
      ์ž‘์„ฑ์ผ <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="date" disabled={sortedReviews.length === 0} />
    </th>
    <th
      className="w-[9%] px-4 py-2 cursor-pointer select-none whitespace-nowrap text-center"
      onClick={() => onSort("reply")}
    >
      ๋‹ต๋ณ€ ์—ฌ๋ถ€ <SortIcon sortKey={sortKey} sortOrder={sortOrder} target="reply" disabled={sortedReviews.length === 0} />
    </th>
  </tr>
</thead>

 

์ด ๋ฐฉ์‹์€ Tailwind๊ฐ€ ๋นŒ๋“œ ์‹œ ๊ณ„์‚ฐํ•˜์ง€ ์•Š๊ณ , ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ Œ๋”๋ง ์‹œ์ ์— ์ง์ ‘ ๊ณ„์‚ฐํ•˜๋ฏ€๋กœ ๋ฐ˜์˜ฌ๋ฆผ ์˜ค์ฐจ๊ฐ€ ์‚ฌ๋ผ์ง€๊ณ  ์Šคํฌ๋กค์ด ์ƒ๊ธฐ์ง€ ์•Š๋Š”๋‹ค.

728x90
๋ฐ˜์‘ํ˜•