0% completed
The calc()
function allows you to perform mathematical calculations to determine CSS property values. This makes it easier to create dynamic layouts without needing to hard-code every value. You can combine different units like percentages and pixels to calculate sizes, margins, paddings, and more.
property: calc(expression);
Explanation:
+
, -
, *
, or /
) to compute a value.%
and px
) or perform operations to make responsive adjustments.In this example, a container's width is set to the full width of its parent minus a fixed amount (such as space for padding or margins). This allows you to maintain a fluid layout while accounting for extra spacing.
Explanation:
calc(100% - 40px)
, meaning it takes up the full available width of its parent minus 40 pixels.In this example, the calc()
function is used to create padding that mixes percentage-based values with fixed pixel values. This can help to ensure consistent spacing across different screen sizes.
Explanation:
calc(2% + 10px)
, which means it will always be 2% of the container’s width plus an extra 10 pixels.The CSS calc()
function is a versatile tool that lets you compute values dynamically, mixing different units if needed.
calc()
when you need flexible dimensions or spacing that adapts to both fixed and relative measurements.With these examples, you now understand how to incorporate calc()
into your CSS to achieve more dynamic and responsive designs.
.....
.....
.....