- Services
- Case Studies
- Technologies
- NextJs development
- Flutter development
- NodeJs development
- ReactJs development
- About
- Contact
- Tools
- Blogs
- FAQ
CSS Margin-Bottom Mastering Space Control
Discover its use cases and available options, including length, percentage, and auto.
Introduction
The margin-bottom CSS property lets you control the space between the bottom of an element and the content below it. This is crucial for creating visually appealing and functional web designs. By tweaking this property, you can add extra space for clarity or reduce it for a more compact layout.
Description
The margin-bottom property sets the space below an element, defining the distance between the element and the content directly beneath it. This is handy for controlling the layout and spacing of web page elements, ensuring a clean and organized design.
The margin-bottom property can take various values, including lengths, percentages, and keywords like auto. Positive values increase the space, while negative values decrease it. It’s important to note that this property doesn’t affect non-replaced inline elements like <span> or <code>.
Syntax
Here’s the basic syntax for using the margin-bottom property in CSS:
/* <length> values */margin-bottom: 10px; /* An absolute length */margin-bottom: 1em; /* Relative to the text size */margin-bottom: 5%; /* Relative to the nearest block container's width */
/* Keyword values */margin-bottom: auto;
/* Global values */margin-bottom: inherit;margin-bottom: initial;margin-bottom: revert;margin-bottom: revert-layer;margin-bottom: unset;Values
The margin-bottom property accepts various values:
- Length: Fixed length values like pixels (
px), ems (em), etc.margin-bottom: 20px; /* 20 pixels of space below the element */margin-bottom: 1em; /* Space equal to the font size of the element */ - Percentage: Relative to the width of the containing block.
margin-bottom: 10%; /* 10% of the width of the containing block */
auto: Browser automatically calculates a suitable margin value.margin-bottom: auto; /* Browser calculates the margin */- Global Values:
inherit,initial,revert,revert-layer, andunset.margin-bottom: inherit; /* Inherits the value from the parent element */margin-bottom: initial; /* Sets the value to its default value */margin-bottom: unset; /* Resets the value to its inherited or initial value */
Formal Definition
| Property | Value |
|---|---|
| Initial Value | 0 |
| Applies To | All elements except elements with table display types other than table-caption, table, and inline-table. It also applies to ::first-letter. |
| Inherited | No |
| Percentages | Refer to the width of the containing block |
| Computed Value | The percentage as specified or the absolute length |
| Animation Type | A length |
Examples
Setting Positive and Negative Bottom Margins
HTML
<div class="container"> <div class="box0">Box 0</div> <div class="box1">Box 1</div> <div class="box2">Box one's negative margin pulls me up</div></div>CSS
.box0 { margin-bottom: 1em; height: 3em;}.box1 { margin-bottom: -1.5em; height: 4em;}.box2 { border: 1px dashed black; border-width: 1px 0; margin-bottom: 2em;}
.container { background-color: orange; width: 320px; border: 1px solid black;}div { width: 320px; background-color: gold;}This example shows how to use both positive and negative margins to control the spacing between elements. Positive margins add extra space, while negative margins reduce it, pulling elements closer together.
Specifications
The margin-bottom property is defined in the CSS Box Model Module Level 3 under the margin-physical section.
Browser Compatibility
The margin-bottom property is widely supported across all major browsers, including:
- Google Chrome 1.0
- Edge 12.0
- Internet Explorer 3.0
- Firefox 1.0
- Opera 3.5
- Safari 1.0
See Also
For further reading and related properties, you may also be interested in:
margin-top,margin-right, andmargin-left- The mapped logical properties:
margin-block-start,margin-block-end,margin-inline-start, andmargin-inline-end - Shorthand properties:
margin,margin-block, andmargin-inline
Browser Compatibility for margin-bottom
You can use the margin-bottom property confidently in your web projects. It’s supported by all major browsers, so you won’t have compatibility issues. Here’s a quick overview of browser support:
| Browser | Minimum Version | Release Date |
|---|---|---|
| Chrome | 1.0 | December 2008 |
| Edge | 12.0 | July 2015 |
| Firefox | 1.0 | November 2004 |
| Internet Explorer | 3.0 | August 1996 |
| Opera | 3.5 | November 1998 |
| Safari | 1.0 | June 2003 |
Related CSS Properties
For more on CSS margins, check out these related properties:
margin-top: Sets the space above an element.margin-right: Sets the space to the right of an element.margin-left: Sets the space to the left of an element.margin: Shorthand to set all four margins at once.
Logical Margin Properties
For more flexibility, explore these logical margin properties:
margin-block-start: Sets the margin at the start of the block.margin-block-end: Sets the margin at the end of the block.margin-inline-start: Sets the margin at the start of the inline direction.margin-inline-end: Sets the margin at the end of the inline direction.margin-block: Shorthand for block-start and block-end margins.margin-inline: Shorthand for inline-start and inline-end margins.
These properties help you control spacing and layout, creating dynamic and responsive web designs.
สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it’s done ที่แผนชัด งบไม่บานปลายแน่นอน
Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่
วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย
TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว
Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์
เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ! พูดคุยกับซีอีโอ
We'll be right here with you every step of the way.
We'll be here, prepared to commence this promising collaboration.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.