Monday 11 March 2019

CSS3 - Box Sizing

Box sizing property is using to change the height and width of element.
Since css2, the box property has worked like as shown below −
width + padding + border = actual visible/rendered width of an element's box
height + padding + border = actual visible/rendered height of an element's box
Means when you set the height and width, it appears little bit bigger then given size cause element boarder and padding added to the element height and width.

CSS2 sizing property

<html>
   <head>
      <style>
         .div1 {
            width: 200px;
            height: 100px;
            border: 1px solid green;
         }
         .div2 {
            width: 200px;
            height: 100px;    
            padding: 50px;
            border: 1px solid pink;
         }
      </style>
   </head>

   <body>
      <div class = "div1">learnsoftware.com</div><br />
      <div class = "div2">learnsoftware.com</div>
   </body>
</html>


CSS3 box sizing property

<html>
   <head>
      <style>
         .div1 {
            width: 300px;
            height: 100px;
            border: 1px solid blue;
            box-sizing: border-box;
         }
         .div2 {
            width: 300px;
            height: 100px;
            padding: 50px;
            border: 1px solid red;
            box-sizing: border-box;
         }
      </style>
   </head>

   <body>
      <div class = "div1">learnsoftware.com</div><br />
      <div class = "div2">learnsoftware.com</div>
   </body>
</html>
Above sample is having same height and width with box-sizing:border-box

No comments:

Post a Comment

Unity Top Download

Latest post

An Introduction to Hybris from basics

An Introduction to Hybris from basics:  -- ecommerce site and PCM(Product content Management) solutions. eg. croma website.  -- having sear...

Popular posts