java 如何将 CSS 用于 Vaadin 组件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14274816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I use CSS for Vaadin components?
提问by Arturas M
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);
回答by raffael
You can create you own custom theme. See https://vaadin.com/book/-/page/themes.creating.htmlhow to do that.
In this theme you have a css style sheet where you can put your rules.
您可以创建自己的自定义主题。请参阅https://vaadin.com/book/-/page/themes.creating.html如何做到这一点。
在这个主题中,您有一个 css 样式表,您可以在其中放置规则。
On every Component you can use the addStyleName function to add an additional class name:
在每个组件上,您都可以使用 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;
}