2

我正在使用 trix 编辑器,例如 <%= f.trix_editor :body, class: 'trix-content form-control', rows: 15 %>

目前按钮是黑色的,显然是翻译成英文的(以及替代文本)。

我应该如何更改按钮的颜色?我尝试过的一切似乎都不起作用。

有没有办法提供德语翻译?我需要我的完整申请完全是德语。

最好的祝福

4

2 回答 2

7

您可以使用 css 更改按钮的背景颜色。

trix-toolbar .trix-button-group button {
  background-color: green;
}

按钮图标是图像,因此您必须替换它们才能自定义图标颜色等。例如,使用 css 删除粗体按钮图标:

trix-toolbar .trix-button-group button.trix-button--icon-bold::before {
  background-image: none;
}

data-trix-attribute您可以通过参考您想要更改的按钮的 javascript 来更改按钮工具提示(用于翻译或其他) 。例如,要更改data-trix-attribute设置为“bold”的粗体按钮(由于浏览器不一致,最好同时设置 theTrix.config.lang和 elementtitle属性):

Trix.config.lang.bold = 'Really Bold';
document.querySelector('button[data-trix-attribute="bold"]').setAttribute('title', 'Really Bold');

以下片段说明了上面的各种变化。

// hover over the now blank bold button in the toolbar to see the tooltip
Trix.config.lang.bold = 'Really Bold';
document.querySelector('button[data-trix-attribute="bold"]').setAttribute('title', 'Really Bold');
trix-toolbar .trix-button-group button {
  background-color: green;
}

trix-toolbar .trix-button-group button.trix-button--icon-bold::before {
  background-image: none;
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.1.1/trix.js"></script>

<trix-editor></trix-editor>

于 2018-07-26T06:19:44.350 回答
0

我知道我真的迟到了,但今天早上我正在考虑做这个问题。有一些解决方案可以替换 Trix使用的图标(Google 的 Material Design Icons)。有人有一个非常巧妙的想法,用 FontAwesome 图标替换它们。

这些是 SVG 图像,因此无法更改颜色。对于我的特殊情况,我使用 webkit 过滤器将颜色从黑色更改为灰色:

trix-toolbar .trix-button--icon {
   -webkit-filter: invert(50%);
}

这应该在 application.scss 中。由于我还没有追查到的原因,将它放在 actiontext.scss 文件中是行不通的,即使它正在被导入到 application.scss 中。

于 2021-06-10T23:43:37.847 回答