Почему document.execCommand ('' backColor '') не работает с переменной css, а foreColor работает? - PullRequest
0 голосов
/ 20 ноября 2018

Мне нужно выполнить команду document.execCommand('backColor') с переменной css , но что-то идет не так.Стиль фона не добавлен.foreColor работает как положено и добавляет цветовой стиль с переменной.Я делаю это в среде Angular 7.

function redBg() {
    document.execCommand('styleWithCSS', true, null);
    document.execCommand('backColor', false, 'var(--red)');
}

function redFg() {
    document.execCommand('styleWithCSS', true, null);
    document.execCommand('foreColor', false, 'var(--red)');
}
.content {
  background: #ccc;
  width: 100%;
}

.button {
  font-size: 20px;
  background: #f00;
  user-select: none;
  margin: 5px;
}

--red: red;
<div class="content" contentEditable="true">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

<div class="button" onmousedown="redBg()">Red bg</div>

<div class="button" onmousedown="redFg()">Red fg</div>

1 Ответ

0 голосов
/ 20 ноября 2018

Аргументом значения должен быть CSS <color> per:

. Для этого требуется, чтобы строка значения передавалась в качестве аргумента значения.

и указывается водин из следующих методов:

https://developer.mozilla.org/en-US/docs/Web/CSS/color_value

Использование пользовательского свойства CSS не является CSS <color>

...