<?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: Aditya Patnaik</title>
    <description>The latest articles on Forem by Aditya Patnaik (@adityapatnaik).</description>
    <link>https://forem.com/adityapatnaik</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%2F419525%2Fa6e8749e-9995-4a92-a59f-4043c77a82a9.jpg</url>
      <title>Forem: Aditya Patnaik</title>
      <link>https://forem.com/adityapatnaik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adityapatnaik"/>
    <language>en</language>
    <item>
      <title>Why padding in a div affects other elements?</title>
      <dc:creator>Aditya Patnaik</dc:creator>
      <pubDate>Thu, 03 Sep 2020 16:20:14 +0000</pubDate>
      <link>https://forem.com/adityapatnaik/why-does-padding-in-a-div-affects-other-elements-3na2</link>
      <guid>https://forem.com/adityapatnaik/why-does-padding-in-a-div-affects-other-elements-3na2</guid>
      <description>&lt;p&gt;This problem is documented in the official MDN docs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By default in the CSS box model, the width and height you assign to an element is applied only to the element's content box. If the element has any border or padding, this is then added to the width and height to arrive at the size of the box that's rendered on the screen. This means that when you set width and height, you have to adjust the value you give to allow for any border or padding that may be added - MDN&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To handle this behavior, we make use of the &lt;code&gt;box-sizing&lt;/code&gt; attribute and set it to &lt;code&gt;border-box&lt;/code&gt; for all elements. Like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&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;blockquote&gt;
&lt;p&gt;&lt;code&gt;border-box&lt;/code&gt; tells the browser to account for any border and padding in the values you specify for an element's width and height. If you set an element's width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width. This typically makes it much easier to size elements. - MDN&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This makes dealing with the sizes of elements much easier, and generally eliminates a number of pitfalls you can stumble on while laying out your content.&lt;/p&gt;

&lt;p&gt;The result of using the box-sizing: border-box; is so much better, many developers want all elements on their pages to work this way.&lt;/p&gt;

&lt;p&gt;Many browsers already use box-sizing: border-box; for many form elements (but not all - which is why inputs and text areas look different at width: 100%&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
