Как использовать css переменные в функции cal c - PullRequest
2 голосов
/ 21 апреля 2020

Я пытаюсь использовать css переменные в css cal c функции, но она не отображается должным образом.

Мой код

font-size: calc(var(--typography-headings-h1-minfontsize) + unquote("px") + (var(--typography-headings-h1-maxfontsize) - var(--typography-headings-h1-minfontsize)) * ((100vw - 320) / (1296 - 320)));

:root {
  --primary-color: #0652dd;
  --secondary-color: #ffffff;

  --navbar-bg-color: #f1f1f1;

  --typography-body-fontsize: 16px;
  --typography-body-family: Merriweather;
  --typography-body-weight: 400;
  --typography-body-color: #000;
  --typography-body-lineheight: 1.5;

  --typography-headings-family: Fira Sans;
  --typography-headings-weight: 400;
  --typography-headings-color: #dd3333;
  --typography-headings-style: normal;
  --typography-headings-letterspacing: 0;
  --typography-headings-texttransform: none;

  --typography-headings-h1-minfontsize: 36;
  --typography-headings-h1-maxfontsize: 60;
  --typography-headings-h1-lineheight: 1.3;
}

h1 {
  font-size: calc(14px + (26 - 14) * ((100vw - 320px) / (1296 - 320)));
  font-size: calc(var(--typography-headings-h1-minfontsize) + unquote("px") + (var(--typography-headings-h1-maxfontsize) - var(--typography-headings-h1-minfontsize) ) * ((100vw - 320) / (1296 - 320))
  );
}
<h1>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Debitis, impedit.</h1>

Ожидаемый результат:

font-size: calc(14px + (26 - 14) * ((100vw - 320px) / (1296 - 320)));

Любая помощь будет оценена

1 Ответ

4 голосов
/ 21 апреля 2020

В CSS нет ничего, что называется unquote("px"), вам нужно умножить на 1px

:root {
  --primary-color: #0652dd;
  --secondary-color: #ffffff;

  --navbar-bg-color: #f1f1f1;

  --typography-body-fontsize: 16px;
  --typography-body-family: Merriweather;
  --typography-body-weight: 400;
  --typography-body-color: #000;
  --typography-body-lineheight: 1.5;

  --typography-headings-family: Fira Sans;
  --typography-headings-weight: 400;
  --typography-headings-color: #dd3333;
  --typography-headings-style: normal;
  --typography-headings-letterspacing: 0;
  --typography-headings-texttransform: none;

  --typography-headings-h1-minfontsize: 36;
  --typography-headings-h1-maxfontsize: 60;
  --typography-headings-h1-lineheight: 1.3;
}

h1 {
  /*font-size: calc(14px + (26 - 14) * ((100vw - 320px) / (1296 - 320)));*/
  font-size: 
     calc(var(--typography-headings-h1-minfontsize)*1px + 
       (
        var(--typography-headings-h1-maxfontsize) - var(--typography-headings-h1-minfontsize)) 
        * 
        ((100vw - 320px) / (1296 - 320)) /* don't forget the px unit for the first 320 */
       );
}
<h1>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Debitis, impedit.</h1>

Связано: Как отладить CSS cal c () value?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...