<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aman Agarwal</title>
    <description>The latest articles on DEV Community by Aman Agarwal (@agarwalamn).</description>
    <link>https://dev.to/agarwalamn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F255597%2F9a5cdb24-3347-4770-9b22-106afa305e9a.jpg</url>
      <title>DEV Community: Aman Agarwal</title>
      <link>https://dev.to/agarwalamn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/agarwalamn"/>
    <language>en</language>
    <item>
      <title>Wait... Where Did My Margin Go? 🤯 (Margin Collapsing Explained)</title>
      <dc:creator>Aman Agarwal</dc:creator>
      <pubDate>Sun, 18 May 2025 16:59:44 +0000</pubDate>
      <link>https://dev.to/agarwalamn/wait-where-did-my-margin-go-margin-collapsing-explained-4jfe</link>
      <guid>https://dev.to/agarwalamn/wait-where-did-my-margin-go-margin-collapsing-explained-4jfe</guid>
      <description>&lt;p&gt;Do you see anything wrong in below image? 👀&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxgngn59ef3dkb5d29gl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqxgngn59ef3dkb5d29gl.png" alt="Image with margin collapsed" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No? 🧐&lt;br&gt;
Let me give you hint, Parent margin is missing.&lt;/p&gt;

&lt;p&gt;I have made a minor change, do you see what I am talking about now?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3q9fxi621az457vnym7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3q9fxi621az457vnym7p.png" alt="Image without margin collapsed" width="800" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is something that tripped me up recently — turns out it’s caused by a little CSS behavior called margin collapsing.&lt;/p&gt;



&lt;p&gt;🤔 So, what is &lt;strong&gt;Margin Collapsing?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As per MDN:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the individual margins (or just one of them, if they are equal), a behavior known as margin collapsing. Note that the margins of floating and absolutely positioned elements never collapse.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In simpler terms:&lt;br&gt;
If two vertical margins meet (like one element’s bottom and the next one’s top), only the larger one is applied, not both.&lt;/p&gt;

&lt;p&gt;This can make it feel like your margins are “disappearing” — which is exactly what I experienced!&lt;/p&gt;



&lt;p&gt;🔧 How to Fix It?&lt;br&gt;
One of the simplest ways is to change the display of the parent element to flex or grid.&lt;br&gt;
This stops margin collapsing from happening altogether. As you see in second image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* or grid */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;🌱 Why This Mattered to Me&lt;br&gt;
I stumbled upon this while debugging a weird layout issue. Margins weren’t stacking like I expected, and it made me question everything 😅&lt;/p&gt;

&lt;p&gt;After some digging, I found this gem of a page:&lt;br&gt;
👉 &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_box_model/Mastering_margin_collapsing" rel="noopener noreferrer"&gt;Mastering Margin Collapsing - MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Highly recommended read if you’ve ever felt CSS was gaslighting you.&lt;/p&gt;




&lt;p&gt;✅ TL;DR&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If vertical margins seem to “disappear”, margin collapsing might be the culprit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Happens between block elements’ top/bottom margins&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid it using display: flex, grid, or some padding&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Would love to hear if you’ve faced this before — or if this helped you spot a sneaky bug. Let me know below! 👇&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Checkout my new project🎀</title>
      <dc:creator>Aman Agarwal</dc:creator>
      <pubDate>Tue, 22 Feb 2022 13:50:51 +0000</pubDate>
      <link>https://dev.to/agarwalamn/checkout-my-new-project-3h8e</link>
      <guid>https://dev.to/agarwalamn/checkout-my-new-project-3h8e</guid>
      <description>&lt;p&gt;Presenting &lt;a href="https://live-board.vercel.app" rel="noopener noreferrer"&gt;liveboard&lt;/a&gt;🎃&lt;/p&gt;

&lt;p&gt;A live board canvas sharing application made on top of nextJS and socket.io.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsnkhobye10b8i9cpgdt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsnkhobye10b8i9cpgdt.png" alt="Project screenshot" width="800" height="547"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Liveboard makes use of socket.io to send the coordinates to draw on the canvas using socket and using HTML canvas to draw the stroke. It also contains tools to change stroke color and stroke width. &lt;/p&gt;

&lt;p&gt;I also tried to implement the Figma-like UI to show users in the lobby in the header along with Figma-like pointer sharing.&lt;/p&gt;

&lt;p&gt;Ending note, there are still some finishing to be done and there is always scope for improvement. Constructive criticism is welcomed🎏&lt;/p&gt;

&lt;p&gt;Tech stack:&lt;br&gt;
Next Js + Socket.io client hosted on vercel&lt;br&gt;
Express + Socket.io hosted on heroku&lt;/p&gt;

&lt;p&gt;Code: &lt;a href="https://github.com/agarwalamn/liveboard" rel="noopener noreferrer"&gt;https://github.com/agarwalamn/liveboard&lt;/a&gt; &lt;br&gt;
PS: I won’t mind if you leave a star😁&lt;/p&gt;

&lt;p&gt;Peace out☮&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Femojipedia-us.s3.amazonaws.com%2Fcontent%2F2017%2F09%2F21%2Fanimoji-alien-emojipedia.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Femojipedia-us.s3.amazonaws.com%2Fcontent%2F2017%2F09%2F21%2Fanimoji-alien-emojipedia.gif" width="760" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>nextjs</category>
      <category>react</category>
    </item>
  </channel>
</rss>
