Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Margin And Padding in TailwindCSS

Margin And Padding in TailwindCSS

? Margin and Padding Utilities in Tailwind CSS

Tailwind makes it simple to control margin and padding with easy-to-use utility classes. These apply spacing outside (margin) or inside (padding) of elements.


1. Margin (m)

Controls the outer space around an element.

Class ExampleCSS EquivalentDescription
m-4margin: 1rem;Margin on all sides
mt-2margin-top: 0.5rem;Top margin
mr-6margin-right: 1.5rem;Right margin
mb-1margin-bottom: 0.25rem;Bottom margin
ml-3margin-left: 0.75rem;Left margin
mx-5margin-left/right: 1.25rem;Horizontal margins
my-2margin-top/bottom: 0.5rem;Vertical margins
-m-2margin: -0.5rem;Negative margin (all sides)

2. Padding (p)

Controls the inner space between content and border.

Class ExampleCSS EquivalentDescription
p-4padding: 1rem;Padding on all sides
pt-2padding-top: 0.5rem;Top padding
pr-6padding-right: 1.5rem;Right padding
pb-1padding-bottom: 0.25rem;Bottom padding
pl-3padding-left: 0.75rem;Left padding
px-5padding-left/right: 1.25rem;Horizontal padding
py-2padding-top/bottom: 0.5rem;Vertical padding

3. Spacing Scale

Tailwind uses a default spacing scale based on rems (1rem = 16px by default):

Class Valuerempx
000
0.50.1252
10.254
1.50.3756
20.58
2.50.62510
30.7512
3.50.87514
4116
51.2520
61.524
71.7528
8232
92.2536
102.540

4. Example Usage

<div class="m-6 p-4 bg-blue-200">  <p class="mb-2">This box has margin 1.5rem and padding 1rem.</p>  <button class="px-3 py-1 bg-blue-500 text-white rounded">Button</button></div>

5. Negative Margins

Sometimes you need to pull elements closer or overlap.

<div class="relative">  <div class="bg-gray-300 p-6">Normal content</div>  <div class="-mt-4 bg-red-400 p-4">Pulled up with negative margin-top</div></div>

If you want, I can also explain how to customize the spacing scale or show responsive margin/padding examples!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql