【问题标题】:Vaadin flow custom stylesVaadin 流自定义样式
【发布时间】:2018-05-04 12:18:55
【问题描述】:

您好,我正在尝试在 vaadin 组件上定义我的自定义样式。我有一个带有styleshtml 文件,它看起来像这样:

<link rel="import" href="../bower_components/vaadin-lumo-styles/color.html">
<link rel="import" href="../bower_components/vaadin-lumo-styles/typography.html">


<dom-module id="css-style-example" theme-for="vaadin-button">
    <template>
        <style include="vaadin-button-default-theme">
        .card {
            box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
            transition: 0.3s;
            width: 40%;
        }
        .card:hover {
            box-shadow: 0 8px 16px 0 rgba(0,0,0,50);
            transform: scale(1.05, 1.05)
        }
        </style>
    </template>
</dom-module>

它是gradle 项目,这个file 位于/src/main/resources/frontend/styles。

我正在尝试在我的button 组件上使用这个style,如下所示:

@HtmlImport("frontend://styles/shared-styles.html")
public class BasePageView extends VerticalLayout { 
    .
    .
    .
    homeButton.setClassName("card");
}

但我不知何故无法让这件事发挥作用。我是css 的新手,请原谅我犯的任何愚蠢错误。

我在 github 上搜索了一些示例,但我有点迷茫,如果有人能向我解释我如何准确地定义 style 为,比如说,vaadin 流,我将不胜感激button ?感谢您的帮助。

【问题讨论】:

    标签: java css frontend vaadin vaadin10


    【解决方案1】:

    使用 &lt;custom-style&gt; 代替 dom-module(针对 vaadin-button),它用于全局样式:

    <custom-style>
      <style>
        .card {
            box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
            transition: 0.3s;
            width: 40%;
        }
        .card:hover {
            box-shadow: 0 8px 16px 0 rgba(0,0,0,50);
            transform: scale(1.05, 1.05)
        }
      </style>
    </custom-style>
    

    有关样式化 Vaadin 组件的更多信息,请通过以下方式阅读这些指南:https://github.com/vaadin/vaadin-themable-mixin/wiki

    【讨论】:

    • 上述链接的 vaadin-themable-mixin 文档的更新 URL 为 github.com/vaadin/vaadin-themable-mixin#readme。内容已从 wiki 移至自述文件。目前旧的 wiki 页面仍然链接到自述文件,但 wiki 页面将来可能会被删除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 2017-02-10
    • 2011-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多