<?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: Obasi Lilian U</title>
    <description>The latest articles on DEV Community by Obasi Lilian U (@obasililian59cell).</description>
    <link>https://dev.to/obasililian59cell</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%2F3912717%2Fdcd8c66c-f6c2-4fe5-b374-975822ec2c6e.png</url>
      <title>DEV Community: Obasi Lilian U</title>
      <link>https://dev.to/obasililian59cell</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/obasililian59cell"/>
    <language>en</language>
    <item>
      <title>From Negative Margins to Clean Layouts: How I Stopped Fighting CSS</title>
      <dc:creator>Obasi Lilian U</dc:creator>
      <pubDate>Mon, 04 May 2026 20:10:15 +0000</pubDate>
      <link>https://dev.to/obasililian59cell/from-negative-margins-to-clean-layouts-how-i-stopped-fighting-css-15hd</link>
      <guid>https://dev.to/obasililian59cell/from-negative-margins-to-clean-layouts-how-i-stopped-fighting-css-15hd</guid>
      <description>&lt;p&gt;Hi everyone! 👋&lt;/p&gt;

&lt;p&gt;I'm Lilian, a frontend developer transitioning from Agricultural Science. This week, I launched my first professional portfolio hub, and I want to share a specific lesson I learned about CSS spacing that changed how I approach layouts.&lt;/p&gt;

&lt;p&gt;The Problem: Forcing Things to Fit&lt;/p&gt;

&lt;p&gt;When I was styling my portfolio, I noticed some elements felt too far apart. My quick fix? Negative margins.&lt;/p&gt;

&lt;p&gt;I wrote code like this:&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="nt"&gt;blockquote&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Pulling it up by force */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On my desktop screen, it looked perfect. But when I checked it on mobile, things started overlapping unpredictably. I was essentially "pulling elements upward by force" instead of letting them flow naturally.&lt;/p&gt;

&lt;p&gt;The Realization&lt;/p&gt;

&lt;p&gt;I realized that negative margins are often a shortcut that fights the document flow. They might solve a visual problem in one specific view, but they break easily when the screen size changes.&lt;/p&gt;

&lt;p&gt;The Solution: Working With the Flow&lt;/p&gt;

&lt;p&gt;Instead of forcing elements to move, I learned to adjust the natural spacing of the elements around them.&lt;/p&gt;

&lt;p&gt;The "pro move" I discovered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduce the &lt;code&gt;margin-bottom&lt;/code&gt; of the element above.&lt;/li&gt;
&lt;li&gt;Or reduce the &lt;code&gt;margin-top&lt;/code&gt; of the element below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So instead of this:&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="c"&gt;/* ❌ The old way */&lt;/span&gt;
&lt;span class="nt"&gt;blockquote&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I did this:&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="c"&gt;/* ✅ The new way */&lt;/span&gt;
&lt;span class="nc"&gt;.intro-section&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Gentle spacing */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="nt"&gt;blockquote&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Natural flow */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Result&lt;/p&gt;

&lt;p&gt;My layout is now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Stable on all screen sizes.&lt;/li&gt;
&lt;li&gt;✅ Easier to maintain.&lt;/li&gt;
&lt;li&gt;✅ Predictable when I add new content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Takeaway&lt;/p&gt;

&lt;p&gt;If you find yourself using negative margins to fix spacing, pause. Ask yourself: Am I fighting the flow?&lt;/p&gt;

&lt;p&gt;Often, the solution isn't to pull harder, but to adjust the space around the elements gently.&lt;/p&gt;

&lt;p&gt;You can see the final result of this lesson in my live portfolio here:&lt;br&gt;
🔗 &lt;a href="https://obasililian59-cell.github.io/Web-development-portfolio/" rel="noopener noreferrer"&gt;Web Development Portfolio Hub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm still learning, but sharing these small wins helps me remember them. Thanks for reading!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>css</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
