Skip to content

Sizing

กำหนดขนาดของ element ด้วย w-*, h-* และ utilities อื่นๆ

ClassCSS
w-0width: 0
w-pxwidth: 1px
w-4width: 1rem
w-64width: 16rem
w-fullwidth: 100%
w-screenwidth: 100vw
w-svwwidth: 100svw
w-dvwwidth: 100dvw
w-1/2width: 50%
w-1/3width: 33.333%
w-autowidth: auto
w-fitwidth: fit-content
w-minwidth: min-content
w-maxwidth: max-content
ClassCSS
h-fullheight: 100%
h-screenheight: 100vh
h-svhheight: 100svh
h-dvhheight: 100dvh
h-autoheight: auto
h-fitheight: fit-content

Tip: ใช้ dvh (dynamic viewport height) แทน vh สำหรับ mobile เพราะรองรับ address bar


ตั้ง width และ height พร้อมกัน:

<div class="size-10">width: 2.5rem; height: 2.5rem;</div>
<div class="size-full">width: 100%; height: 100%;</div>
ClassCSS
size-4width: 1rem; height: 1rem
size-fullwidth: 100%; height: 100%
size-1/2width: 50%; height: 50%

<div class="min-h-screen">อย่างน้อยเต็มหน้าจอ</div>
<div class="max-w-xl mx-auto">Container กว้างสูงสุด 36rem</div>
<div class="min-w-0">สำหรับ flexbox overflow</div>
ClassEffect
min-h-0min-height: 0
min-h-fullmin-height: 100%
min-h-screenmin-height: 100vh
max-w-xsmax-width: 20rem
max-w-smmax-width: 24rem
max-w-mdmax-width: 28rem
max-w-lgmax-width: 32rem
max-w-xlmax-width: 36rem
max-w-2xlmax-width: 42rem
max-w-nonemax-width: none

<div class="aspect-video">16:9 ratio</div>
<div class="aspect-square">1:1 ratio</div>
<img class="aspect-[4/3] object-cover" src="..." />
ClassRatio
aspect-autoauto
aspect-square1 / 1
aspect-video16 / 9
aspect-[4/3]4 / 3 (arbitrary)

ตัวอย่างการใช้งาน

Section titled “ตัวอย่างการใช้งาน”
<!-- Full-height page -->
<div class="min-h-dvh flex flex-col">
<header class="h-16">Header</header>
<main class="flex-1">Content</main>
<footer class="h-20">Footer</footer>
</div>
<!-- Responsive image -->
<div class="aspect-video w-full max-w-2xl">
<img class="size-full object-cover rounded-lg" src="..." />
</div>