Размеры
Утилиты для установки ширины элемента
Используйте w-{number}
или w-px
, чтобы установить элемент на фиксированную ширину.
<div class="w-96 ..."></div>
<div class="w-80 ..."></div>
<div class="w-64 ..."></div>
<div class="w-48 ..."></div>
<div class="w-40 ..."></div>
<div class="w-32 ..."></div>
<div class="w-24 ..."></div>
Используйте w-{fraction}
или w-full
, чтобы задать ширину элемента в процентах.
<div class="flex ...">
<div class="w-1/2 ... ">w-1/2</div>
<div class="w-1/2 ... ">w-1/2</div>
</div>
<div class="flex ...">
<div class="w-2/5 ...">w-2/5</div>
<div class="w-3/5 ...">w-3/5</div>
</div>
<div class="flex ...">
<div class="w-1/3 ...">w-1/3</div>
<div class="w-2/3 ...">w-2/3</div>
</div>
<div class="flex ...">
<div class="w-1/4 ...">w-1/4</div>
<div class="w-3/4 ...">w-3/4</div>
</div>
<div class="flex ...">
<div class="w-1/5 ...">w-1/5</div>
<div class="w-4/5 ...">w-4/5</div>
</div>
<div class="flex ...">
<div class="w-1/6 ...">w-1/6</div>
<div class="w-5/6 ...">w-5/6</div>
</div>
<div class="w-full ...">w-full</div>
Используйте w-screen
, чтобы элемент занимал всю ширину области просмотра.
<div class="w-screen">
<!-- ... -->
</div>
The w-auto
utility can be useful if you need to remove an element’s assigned width under a specific condition, like at a particular breakpoint:
<div class="w-full md:w-auto">
<!-- ... -->
</div>
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:w-full
to only apply the w-full
utility on hover.
<div class="w-1/2 hover:w-full">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:w-full
to apply the w-full
utility at only medium screen sizes and above.
<div class="w-1/2 md:w-full">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
По умолчанию масштаб ширины Tailwind представляет собой комбинацию шкалы интервалов по умолчанию, а также некоторых дополнительных значений, специфичных для ширины.
Вы можете настроить масштаб интервалов, отредактировав theme.spacing
или theme.extend.spacing
в вашем файле tailwind.config.js
.
module.exports = {
theme: {
extend: {
spacing: {
'128': '32rem',
}
}
}
}
Чтобы настроить ширину отдельно, используйте раздел theme.width
Вашего файла tailwind.config.js
.
module.exports = {
theme: {
extend: {
width: {
'128': '32rem',
}
}
}
}
Дополнительные сведения о настройке темы по умолчанию смотрите в документации настройка темы.
If you need to use a one-off width
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<div class="w-[32rem]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.