Day 24: Unit 1, 2
cm
inch
mm
px
pc
pt
em
ch
rem
vw
vh
%
- 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-color: aqua;
}
.div1{
background-color: blueviolet;
width: calc(100% - 200px);
height: 300px;
color: azure;
}
</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:
Comments
Post a Comment