<?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: Usama Jamil</title>
    <description>The latest articles on DEV Community by Usama Jamil (@usamajamil67).</description>
    <link>https://dev.to/usamajamil67</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%2F728502%2F91fd5e52-f148-42d4-b8c7-3da54958d5ab.png</url>
      <title>DEV Community: Usama Jamil</title>
      <link>https://dev.to/usamajamil67</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/usamajamil67"/>
    <language>en</language>
    <item>
      <title>Simplest way to center a div</title>
      <dc:creator>Usama Jamil</dc:creator>
      <pubDate>Tue, 23 Aug 2022 20:23:00 +0000</pubDate>
      <link>https://dev.to/usamajamil67/simplest-way-to-center-a-div-85i</link>
      <guid>https://dev.to/usamajamil67/simplest-way-to-center-a-div-85i</guid>
      <description>&lt;p&gt;As a web developer sometimes centering a div is the toughest job ever.&lt;br&gt;
&lt;strong&gt;So I am here with a coolest and the easiest way to center a div.&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;So here's the html code&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
    &amp;lt;style&amp;gt;
    &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div id="parentContainer"&amp;gt;
        &amp;lt;div id="childContainer"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I have made two divs in the body. One is with id &lt;strong&gt;parentContainer&lt;/strong&gt; and the other one is &lt;strong&gt;childContainer&lt;/strong&gt;.&lt;br&gt;
&lt;em&gt;Let me share you the css code.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#parentContainer{
    width: 400px;
    height: 400px;
    background-color: brown;
}
#childContainer{
    width: 100px;
    height: 100px;
    background-color: black;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;I just simply gave &lt;strong&gt;height of 400px&lt;/strong&gt; and &lt;strong&gt;width of 400px&lt;/strong&gt; and the &lt;strong&gt;background-color brown&lt;/strong&gt; to the &lt;strong&gt;parentContainer&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Similarly I gave &lt;strong&gt;height of 100px&lt;/strong&gt; and &lt;strong&gt;width of 100px&lt;/strong&gt; and the &lt;strong&gt;background-color black&lt;/strong&gt; to the &lt;strong&gt;childContainer&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Our div is not centered yet, lemme show you guys&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--56_PWqAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f023u5q29bvvvel349r3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--56_PWqAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f023u5q29bvvvel349r3.PNG" alt="Image description" width="639" height="545"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Position property in css is used to set how element is positioned on the page. The default value for position element is &lt;strong&gt;static&lt;/strong&gt;. The other values for position element are &lt;strong&gt;relative, absolute, fixed and sticky.&lt;/strong&gt;&lt;br&gt;
Now if we set &lt;strong&gt;position: absolute;&lt;/strong&gt; to a DOM element it becomes absolute with respect to whole page. This would be useful if we want to center the div with respect to whole page.&lt;/p&gt;

&lt;p&gt;On the other hand giving &lt;strong&gt;position: relative;&lt;/strong&gt; to the parent element, makes the children element (with &lt;strong&gt;position: absolute;&lt;/strong&gt;) absolute, &lt;strong&gt;related to the parent element , not to the whole page.&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Now if we mention &lt;em&gt;top: 0;&lt;/em&gt;, &lt;em&gt;left: 0;&lt;/em&gt;, &lt;em&gt;bottom: 0;&lt;/em&gt; and &lt;em&gt;right: 0;&lt;/em&gt;,&lt;/strong&gt; with &lt;strong&gt;margin: auto;&lt;/strong&gt; and position elements in containers, &lt;strong&gt;it centers our div.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#parentContainer{
    position: relative;
    width: 400px;
    height: 400px;
    background-color: brown;
}
#childContainer{
    position: absolute;
    width: 100px;
    height: 100px;
    background-color: black;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4sYbjnJU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/057cy6y2mv2pzvasv28h.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4sYbjnJU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/057cy6y2mv2pzvasv28h.PNG" alt="Image description" width="501" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Congratulations You have set your div to center.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>{Completed my Hacktoberfest 2021-}</title>
      <dc:creator>Usama Jamil</dc:creator>
      <pubDate>Tue, 19 Oct 2021 13:08:16 +0000</pubDate>
      <link>https://dev.to/usamajamil67/completed-my-hacktoberfest-2021--2jki</link>
      <guid>https://dev.to/usamajamil67/completed-my-hacktoberfest-2021--2jki</guid>
      <description>&lt;p&gt;ALHAMDULILLAH, completed my first hacktoberfest 2021. &lt;/p&gt;

</description>
      <category>hacktoberfest</category>
    </item>
  </channel>
</rss>
