简体   繁体   English

如何将CSS用于Vaadin组件?

[英]How can I use CSS for Vaadin components?

I seem to be seeing examples, where people answer to questions how to get some specific behavior from components by adding CSS code, however nobody seems to explain how to use that CSS code to connect it to Java components... 我似乎看到了一些例子,人们通过添加CSS代码回答问题如何从组件中获取某些特定行为,但似乎没有人解释如何使用该CSS代码将其连接到Java组件......

.v-table-body{
  overflow: hidden !important;
}

How do I use for instance this code on my table that I create? 我如何在我创建的表上使用此代码?

Table table = new Table(caption);

    table.addContainerProperty("Visit ID", Long.class, null);

You can create you own custom theme. 您可以创建自己的自定义主题。 See https://vaadin.com/book/-/page/themes.creating.html how to do that. 请参阅https://vaadin.com/book/-/page/themes.creating.html如何操作。
In this theme you have a css style sheet where you can put your rules. 在这个主题中,你有一个css样式表,你可以在其中放置规则。

On every Component you can use the addStyleName function to add an additional class name: 在每个Component上,您可以使用addStyleName函数添加其他类名:

Table table = new Table("MyCaption");
table.addStyleName("mystyle");

Now you can use this in your style sheet: 现在您可以在样式表中使用它:

@import "../reindeer/styles.css";

.mystyle{
  overflow: hidden !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM