【问题标题】:How to define a style of element using external CSS in mxGraph?如何在 mxGraph 中使用外部 CSS 定义元素样式?
【发布时间】:2020-05-12 19:10:23
【问题描述】:

我正在尝试在 mxGraph 中创建工具栏:

let divForToolbar = document.createElement("div");
divForToolbar.classList.add("toolbar")
let toolbar = new mxToolbar(divForToolbar);

然后,我导入包含类工具栏的 css 样式表。但是它里面的“工具栏”类中定义的所有样式都不起作用。

官方文档提供了在 JS 代码中使用 mxStylesheet 和 mxConstants 来定义样式,或者像这样定义内联样式:

divForToolbar.style.overflow = 'auto';

但我认为在 JS 中定义样式是一种不好的做法。如何在外部 CSS 中正确定义样式?

【问题讨论】:

  • 您是否调查过样式表中的样式没有被应用的原因?样式表加载好吗?样式是否被覆盖?
  • 样式适用于同一页面上的其他元素,如导航栏和按钮,但不适用于 mxToolbar

标签: javascript css mxgraph


【解决方案1】:

您可以使用现有的类名或添加容器工具栏 (editor.setToolbarContainer)。 https://jgraph.github.io/mxgraph/javascript/examples/toolbar.html https://jgraph.github.io/mxgraph/javascript/examples/uiconfig.html

在更复杂的问题中覆盖toolbar.addMode 方法。它帮助我创建自己的样式工具栏。

【讨论】:

    猜你喜欢
    • 2017-08-03
    • 2019-12-21
    • 2011-06-14
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多