<?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>Forem: Jyoutis</title>
    <description>The latest articles on Forem by Jyoutis (@jyotiux).</description>
    <link>https://forem.com/jyotiux</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%2F3474628%2Ffa05073f-d3bf-46e5-be55-d80ffa564052.png</url>
      <title>Forem: Jyoutis</title>
      <link>https://forem.com/jyotiux</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jyotiux"/>
    <language>en</language>
    <item>
      <title>Flexbox Centering</title>
      <dc:creator>Jyoutis</dc:creator>
      <pubDate>Tue, 02 Sep 2025 04:42:00 +0000</pubDate>
      <link>https://forem.com/jyotiux/flexbox-centering-1a7a</link>
      <guid>https://forem.com/jyotiux/flexbox-centering-1a7a</guid>
      <description>&lt;p&gt;Once I gave Flexbox a real try, it finally clicked. I realized I only needed three lines of CSS to center elements both horizontally and vertically.&lt;/p&gt;

&lt;p&gt;The Flexbox Formula to center anything inside a container using Flexbox: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Add display: flex to the parent container. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use justify-content: center to center horizontally. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use align-items: center to center vertically. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTML 
&amp;lt;div class="parent-element"&amp;gt; 
&amp;lt;div class="child-element"&amp;gt;Child 1&amp;lt;/div&amp;gt; 
&amp;lt;div class="child-element"&amp;gt;Child 2&amp;lt;/div&amp;gt; 
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CSS 
.parent-element { 
background-color: #999; 
border: 4px solid #000; 
display: flex; 
justify-content: center; 
align-items: center; 
height: 200px; 
} 
.child-element { 
font-family: sans-serif; 
font-size: 18px; 
text-align: center; 
color: #fff; 
background-color: #1a8446; 
padding: 3em; 
margin: 7px; 
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;display: flex&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;turns the container into a flexbox.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;justify-content: center&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;aligns child elements horizontally (main axis). &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;align-items: center&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;aligns them vertically (cross axis). &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting a height on the parent is necessary to see vertical centering.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I’m Going to Try Next
&lt;/h2&gt;

&lt;p&gt;Here’s what I’m curious to explore as I keep learning Flexbox:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Play with flex-direction to see how it affects layout flow.
&lt;/li&gt;
&lt;li&gt;Use gap instead of margins to space out elements (cleaner).
&lt;/li&gt;
&lt;li&gt;Explore flex-wrap to understand how Flexbox behaves with multiple lines of content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's connect on &lt;a href="https://www.linkedin.com/in/jyotisingh-52a447259/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;—I'd love to network.&lt;/p&gt;

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