Curriculum
Course: CSS
Login

Curriculum

CSS

CSS INTRODUCTION

0/1

CSS Selectors

0/1

CSS Comments

0/1

CSS Padding

0/1

CSS Box Model

0/1

CSS Combinators

0/1

CSS Pseudo-classes

0/1

CSS Pseudo-elements

0/1

CSS Dropdowns

0/1

CSS Image Gallery

0/1

CSS Image Sprites

0/1

CSS Counters

0/1

CSS Website Layout

0/1

CSS Specificity

0/1

CSS Math Functions

0/1
Text lesson

CSS Math Functions

CSS mathematical functions enable the utilization of mathematical expressions as property values. Among these functions are calc(), max(), and min(), each serving distinct purposes.

The calc() Function

The calc() function computes a calculation to be utilized as the property’s value.

CSS Syntax

calc(expression)

Value

Description

expression

Required: A mathematical expression whose result will be used as the value. The following operators can be used: +, -, *, /.

Consider the following example:

Example 

Use `calc()` to determine the width of a `<div>` element:

#div1 {
  position: absolute;
  left: 50px;
  width: calc(100% – 100px);
  border: 1px solid black;
  background-color: yellow;
  padding: 5px;
}

The max() Function

The max() function selects the highest value among a list of comma-separated values to serve as the property value.

CSS Syntax

max(value1value2, …)

Value

Description

value1, value2, …

Required: A list of comma-separated values, from which the largest value is selected.

Example 

Utilize the max() function to establish the width of #div1 as the maximum value between 50% and 300px.

#div1 {
  background-color: yellow;
  height: 100px;
  width: max(50%, 300px);
}

The min() Function

The min() function selects the smallest value among a list of comma-separated values to serve as the property value.

CSS Syntax

min(value1value2, …)

Value

Description

value1, value2, …

Required: A list of comma-separated values, from which the smallest value is selected.

Consider the following example:

Example 

Utilize the min() function to establish the width of #div1 as the minimum value between 50% and 300px.

#div1 {
  background-color: yellow;
  height: 100px;
  width: min(50%, 300px);
}

All CSS Math Functions

Function

Description

calc()

Enables you to perform calculations to determine CSS property values.

max()

Uses the largest value from a comma-separated list as the property value.

min()

Uses the smallest value from a comma-separated list as the property value.