Tailwind CSS - 间距
Tailwind CSS 间距包括内边距(Padding)、外边距(Margin)和间距(Space Between)。这些是 Tailwind 间距的重要概念,要在任何元素上创建内部或外部空间,您需要使用内边距和外边距。如果您想在子元素之间添加固定间距,则必须使用 space between。
Tailwind CSS 间距参考
以下主题可用于在元素上创建间距。
| 主题 | 描述 | 示例 |
|---|---|---|
| Tailwind CSS - 内边距 | 内边距用于在任何元素上创建内部空间。 |
|
| Tailwind CSS - 外边距 | 外边距用于在任何元素上创建外部空间。 |
|
| Tailwind CSS - 间距 | 间距用于在任何容器的子元素之间创建间隙或空间。 |
|
Tailwind CSS 间距示例
在以下示例中,我们将涵盖上述每个主题中的任意一个类。
示例
<!DOCTYPE html>
<html>
<head>
<!-- Tailwind CSS CDN Link -->
<script src="https://cdn.tailwindcss.com?plugins=aspect-ratio">
</script>
</head>
<body>
<div class="m-5">
<p class="text-3xl font-bold">
Tailwind CSS Spacing
</p>
<p>
It may seems that Padding and Margin is giving the
same outcome but there is catch. We have applied the
padding class on parent div and margin class on child div.
</p>
<div>
<p class="text-xl font-bold">
Tailwind CSS Padding
</p>
<div class="p-4 m-2 border border-green-600
bg-green-200 w-max">
<div class="bg-green-600 w-16 h-16"></div>
</div>
<p class="text-xl font-bold">
Tailwind CSS Margin
</p>
<div class="m-2 border border-green-600
bg-green-200 w-max">
<div class="m-4 bg-green-600 w-16 h-16"></div>
</div>
<p class="text-xl font-bold">
Tailwind CSS Space Between
</p>
<div class="flex space-x-4">
<div class="bg-green-600 w-16 h-16"></div>
<div class="bg-green-600 w-16 h-16"></div>
</div>
</div>
</body>
</html>

