<?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: Abdulmujeeb Mohammed</title>
    <description>The latest articles on DEV Community by Abdulmujeeb Mohammed (@topsimpa).</description>
    <link>https://dev.to/topsimpa</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%2F3343728%2Fc16c1dbd-4e55-4165-8b49-391bd3b3d0a0.jpg</url>
      <title>DEV Community: Abdulmujeeb Mohammed</title>
      <link>https://dev.to/topsimpa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/topsimpa"/>
    <language>en</language>
    <item>
      <title>Understanding Sizing in CSS Flexbox (A Practical Guide)</title>
      <dc:creator>Abdulmujeeb Mohammed</dc:creator>
      <pubDate>Sat, 25 Apr 2026 02:53:42 +0000</pubDate>
      <link>https://dev.to/topsimpa/understanding-sizing-in-css-flexbox-a-practical-guide-3dk7</link>
      <guid>https://dev.to/topsimpa/understanding-sizing-in-css-flexbox-a-practical-guide-3dk7</guid>
      <description>&lt;p&gt;The first time I really tried to understand sizing in Flexbox, I got stuck. Not because I didn’t understand &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt;.Not because I didn’t know &lt;code&gt;flex-grow&lt;/code&gt; or &lt;code&gt;flex-shrink&lt;/code&gt;. But because &lt;strong&gt;everything I thought I knew about sizing suddenly stopped applying&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In normal layout, things feel predictable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block elements fill width&lt;/li&gt;
&lt;li&gt;Height depends on content&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; behave like firm instructions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then Flexbox shows up… and starts bending those rules.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Moment Things Started Breaking
&lt;/h2&gt;

&lt;p&gt;I remember setting &lt;code&gt;width&lt;/code&gt; on a flex item and expecting it to behave normally.It didn’t.Then I tried adjusting &lt;code&gt;height&lt;/code&gt;. Still weird.&lt;br&gt;
Then I added &lt;code&gt;align-items&lt;/code&gt;, and suddenly things stretched in ways I didn’t expect.&lt;/p&gt;

&lt;p&gt;At that point, it felt like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Flexbox doesn’t respect width and height.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But that’s not true.&lt;/p&gt;

&lt;p&gt;Flexbox &lt;strong&gt;does respect them&lt;/strong&gt; — just not in the way we’re used to.&lt;/p&gt;


&lt;h2&gt;
  
  
  What up with Flexbox?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Flexbox doesn’t think in &lt;strong&gt;horizontal vs vertical&lt;/strong&gt;&lt;br&gt;
It thinks in &lt;strong&gt;main axis vs cross axis&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And once I accepted that, things started making sense.&lt;/p&gt;


&lt;h2&gt;
  
  
  Step 1: The Container Is Not the Problem
&lt;/h2&gt;

&lt;p&gt;Let’s start simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;style=&lt;/span&gt;&lt;span class="s"&gt;"display: flex;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;div&lt;/code&gt; is still a &lt;strong&gt;block element&lt;/strong&gt;.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffnag0xsbttbewvbbycwg.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%2Ffnag0xsbttbewvbbycwg.png" alt="flex container" width="473" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It still fills its parent’s width&lt;/li&gt;
&lt;li&gt;Its height still depends on content&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;display: flex&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; change how the container behaves outside&lt;br&gt;
It only changes how its children are laid out&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This was my first misconception.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2: Everything Depends on Direction
&lt;/h2&gt;

&lt;p&gt;Flexbox introduces a new idea: &lt;strong&gt;axes&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;flex-direction&lt;/th&gt;
&lt;th&gt;Main Axis&lt;/th&gt;
&lt;th&gt;Cross Axis&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;row&lt;/td&gt;
&lt;td&gt;horizontal&lt;/td&gt;
&lt;td&gt;vertical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;column&lt;/td&gt;
&lt;td&gt;vertical&lt;/td&gt;
&lt;td&gt;horizontal&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This one property controls everything.&lt;/p&gt;

&lt;p&gt;And I mean everything.&lt;/p&gt;

&lt;h2&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%2Fohvq2uguip3wfy8pldm9.png" alt="flex axes" width="493" height="270"&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Step 3: The Real Players in Sizing
&lt;/h2&gt;

&lt;p&gt;Once axes are defined, sizing becomes a game between a few properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;flex-basis&lt;/code&gt;: starting size (main axis)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-grow&lt;/code&gt;: how items expand&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;flex-shrink&lt;/code&gt;: how items shrink&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;align-items&lt;/code&gt;: cross-axis behavior&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;width&lt;/code&gt; / &lt;code&gt;height&lt;/code&gt;: physical dimensions (sometimes ignored!)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Let’s Talk About Row (Where Most People Start)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&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="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;row&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;ul&gt;
&lt;li&gt;Main axis: &lt;strong&gt;horizontal&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Cross axis: &lt;strong&gt;vertical&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What Happens to Width?
&lt;/h3&gt;

&lt;p&gt;This is the main axis now.&lt;/p&gt;

&lt;p&gt;So Flexbox asks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do you have a &lt;code&gt;width&lt;/code&gt;?  &lt;code&gt;Yes&lt;/code&gt; use it as a starting point&lt;/li&gt;
&lt;li&gt;If not, do you have &lt;code&gt;flex-basis&lt;/code&gt;? &lt;code&gt;Yes&lt;/code&gt;, use that&lt;/li&gt;
&lt;li&gt;Otherwise: use content size&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extra space? &lt;code&gt;flex-grow&lt;/code&gt; distributes it&lt;/li&gt;
&lt;li&gt;Not enough space? &lt;code&gt;flex-shrink&lt;/code&gt; reduces it&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What Happens to Height? This is cross-axis now.
&lt;/h3&gt;

&lt;p&gt;Flexbox handles it differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;height&lt;/code&gt; is set, it uses it&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;align-items: stretch&lt;/code&gt; (default), fills container height&lt;/li&gt;
&lt;li&gt;Otherwise, content height&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&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%2F0dmbuwutws31445ze963.png" alt="flex items sizing" width="641" height="339"&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Then I Switched to Column… and Everything Broke Again
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&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="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&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;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Main axis, &lt;strong&gt;vertical&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Cross axis, &lt;strong&gt;horizontal&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything flips.&lt;/p&gt;




&lt;h2&gt;
  
  
  Column Direction (The Part That Confuses Everyone)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Height Becomes the Main Axis
&lt;/h3&gt;

&lt;p&gt;Now Flexbox treats &lt;strong&gt;height&lt;/strong&gt; the way it treated width before.&lt;/p&gt;

&lt;p&gt;It asks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do you have a &lt;code&gt;height&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Else, do you have &lt;code&gt;flex-basis&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Else use content size&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extra vertical space, &lt;code&gt;flex-grow&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Not enough,&lt;code&gt;flex-shrink&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Width Becomes Cross Axis
&lt;/h3&gt;

&lt;p&gt;Now width behaves like height did before:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;width&lt;/code&gt; is set,use it&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If not:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;align-items: stretch&lt;/code&gt;, fill container width&lt;/li&gt;
&lt;li&gt;Else, content width&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&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%2Flflgq8an5frqse7jd0sq.png" alt="flex item sizing" width="627" height="325"&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  The Realization That Tied Everything Together
&lt;/h2&gt;

&lt;p&gt;After going back and forth enough times, I realized:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Flexbox doesn’t randomly ignore properties&lt;br&gt;
It just &lt;strong&gt;prioritizes based on the axis&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  The Rule That Finally Made It Click
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Main axis, controlled by flex properties&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Cross axis, controlled by alignment&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; only matter when they align with the axis being calculated&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  One Last Correction I Wish I Knew Earlier
&lt;/h2&gt;

&lt;p&gt;I used to think:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“&lt;code&gt;flex-basis&lt;/code&gt; is the minimum size”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s wrong.&lt;/p&gt;

&lt;p&gt;It’s actually:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The starting size before growing or shrinking&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That small misunderstanding caused a lot of confusion for me.&lt;/p&gt;




&lt;h2&gt;
  
  
  How I Debug Flexbox Now
&lt;/h2&gt;

&lt;p&gt;Whenever something looks off, I ask:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is the &lt;strong&gt;main axis&lt;/strong&gt;?&lt;/li&gt;
&lt;li&gt;What is the &lt;strong&gt;starting size&lt;/strong&gt; (&lt;code&gt;flex-basis&lt;/code&gt; / width / height)?&lt;/li&gt;
&lt;li&gt;Is there &lt;strong&gt;extra space or overflow&lt;/strong&gt;?&lt;/li&gt;
&lt;li&gt;What is controlling the &lt;strong&gt;cross axis&lt;/strong&gt; (&lt;code&gt;align-items&lt;/code&gt;)?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And suddenly, it’s no longer magic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Flexbox feels confusing because it asks you to stop thinking in fixed dimensions and start thinking in &lt;strong&gt;relationships&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Between items&lt;/li&gt;
&lt;li&gt;Between axes&lt;/li&gt;
&lt;li&gt;Between available space and constraints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you make that mental switch, Flexbox stops fighting you…&lt;br&gt;
and starts working with you.&lt;/p&gt;




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