[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/CSS/Guides/Values_and_units/Using_math_functions [Back]  [Original]

Using CSS math functions - CSS: Cascading Style Sheets | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Using CSS math functions

CSS height, animation-duration, font-size .

rem, vw, % CSS HTML .

, . .

  1. "navbar " .
  2. .
  3. font-size .

, . JavaScript .

, CSS . JavaScript .

, 20 . .

In this article

calc():

. calc() .

calc() CSS , , , . % px CSS .

calc() , . :

css
property: calc(expression);

calc()

calc() .

css
div {
  background-color: black;
  margin: 4px 0;
  width: 100%;
}

div > code {
  display: block;
  background-color: red;
  color: white;
  height: 48px;
}

.calc1 > code {
  /*  width: `110px` */
  width: calc(10px + 100px);
}

.calc2 > code {
  /*  width: `10em` */
  width: calc(2em * 5);
}

.calc3 > code {
  /*  width:    . */
  width: calc(100% - 32px);
}

.calc4 > code {
  --predefined-width: 100%;
  /*  width:    . */
  width: calc(var(--predefined-width) - calc(16px * 2));
}

min():

CSS . , " " "500 " . CSS min() .

min() . .

css
property: min(<first value>, <second value>, <third value>, ...);

% px .

min()

min() .

css
div {
  background-color: black;
  margin: 4px 0;
  width: 100%;
}

div > code {
  display: block;
  background-color: darkblue;
  color: white;
  height: 48px;
}

.min1 > code {
  /*  width:    . */
  /*     `50%`   . */
  width: min(9999px, 50%);
}

.min2 > code {
  /*  width:    . */
  /*     `100%`   . */
  width: min(9999px, 100%);
}

.min3 > code {
  /*  width:    . */
  /*     `120px`   . */
  width: min(120px, 150px, 90%);
}

.min4 > code {
  /* Output width:    . */
  /*     `80px`   . */
  width: min(80px, 90%);
}

max():

min() , CSS . , " " "500 " . CSS max() .

max() . .

css
property: max(<first value>, <second value>, <third value>, ...);

% px

min() max() .

max()

max() .

css
div {
  background-color: black;
  margin: 4px 0;
  width: 100%;
  height: 48px;
}

div > code {
  display: block;
  background-color: darkmagenta;
  color: white;
  height: 48px;
}

.max1 > code {
  /*  width:    . */
  /*     `50%`   . */
  width: max(50px, 50%);
}

.max2 > code {
  /*  width:    . */
  /*     `100%`   . */
  width: max(50px, 100%);
}

.max3 > code {
  /*  width:    . */
  /*     `90%`   . */
  width: max(20px, 50px, 90%);
}

.max4 > code {
  /*  width:    . */
  /*     `80%`   . */
  width: max(80px, 80%);
}

clamp():

clamp() min() max() . clamp() , , . .

css
property: clamp(<minimum value>, <value to be clamped>, <maximum value>);
  • , .
  • , .
  • , .

% px

clamp()

clamp() .

css
div {
  background-color: black;
  margin: 4px 0;
  width: 100%;
  height: 48px;
}

div > code {
  display: block;
  background-color: darkgreen;
  color: white;
  height: 48px;
}

.clamp1 > code {
  /*  width:    . */
  /*     `20%`   . */
  width: clamp(20%, 1px, 80%);
}

.clamp2 > code {
  /*  width:    . */
  /*     `90%`   . */
  width: clamp(10%, 9999px, 90%);
}

.clamp3 > code {
  /* Output width: `125px` */
  width: clamp(125px, 1px, 250px);
}

.clamp4 > code {
  /* Output width: `150px` */
  width: clamp(25px, 9999px, 150px);
}

CSS

DOM , calc(), min(), max(), clamp() . , , 3D , CSS .


Web Proxy Viewer  |  New URL  |  Original Page