Day 24: Unit 1, 2

 cm

inch

mm

px

pc

pt

em

ch

rem

vw

vh 

%

  1. calc()
  • When specifying CSS property values, you can conduct computations using the calc() CSS function
  •  Anywhere a "length," "frequency," "angle," "time," "percent," "number," or "integer" is permitted, it can be used. 
  • Operations like addition, subtraction, multiplication and division can also be performed inside the calc() function.
  • Example :
    • width: calc(180% - 20px);
    • width: calc(5em * 2);
    • z-index : calc(5/2)
       
       
  • Example :

width: calc(100% - 200px); 

The above example will calculate the width mentioned inside calc() function and generate suitable width after performing calculation. It will calculate 100% width of the element, then subtract 200px from it, giving us the final width.

       
       

 

  • Output :

 

       

 

       

 

  • Code :

 

<!DOCTYPE html>

<html>

<head>

    <style>

        body{

            background-coloraqua;

        }

       .div1{

        background-colorblueviolet;

        widthcalc(100% - 200px);

        height300px;

        colorazure;

       }

    </style>

</head>

<body>

<div class="div1">

    Width of this div will be calculated in the calc() function.

</div>

</body>

</html>



  • To see additional examples, click the following link:

https://developer.mozilla.org/en-US/docs/Web/CSS/calc

Comments

Popular posts from this blog

else-if condition in if-else statements: Concatenation in JavaScript :

Day 9: CSS - Font Formate

Day 28: CSS Animation, CSS Transition Animation Box size