如何在Vaadin Flow中使用CSS网格替代Framework 8的GridLayout? [英] How to use a css grid in Vaadin Flow as replacement for Framework 8's GridLayout?

查看:115
本文介绍了如何在Vaadin Flow中使用CSS网格替代Framework 8的GridLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有的Vaadin 8应用程序迁移到Vaadin 12,并且需要知道如何在Vaadin 12中重新创建Vaadin 8的GridLayout的功能。





以及类似的样式(基本上只是向您的颜色添加颜色样式表进行验证,就可以使用)



这是输出:



我没有找到确切的参数在Vaadin页面上,介绍了如何使用网格样式,但是本教程看起来很有前景《网格的完整指南》 。否则,关于Vaadin的内容应该没有什么特别的。



此外,目录中似乎还有一个加载项,这可能对 Css网格布局(不过,我还没有亲自尝试过)


I'm trying to migrate an existing Vaadin 8 application to Vaadin 12 and need to know how to recreate the functionality of Vaadin 8's GridLayout in Vaadin 12.

According to Vaadin Docs a GridLayout can be replaced in Vaadin 12 by: "Use Div together with the new CSS Grid functionality that is supported in most browsers"

Unfortunately it's not totally clear how exactly this can be done.

Lets assume that I have a Vaadin composite "HelloGrid":

@StyleSheet("styles/hello-grid.css")
public class HelloGrid extends Composite<Div> {

   public HelloGrid(){

     // EDIT: This line is my solution to the question
     getElement().getClassList().add("hello-grid");

     Label labelOne = new Label();
     labelOne.addClassName("label-one");

     Label labelTwo = new Label();
     labelTwo.addClassName("label-two");

     add(labelOne);
     add(labelTwo);
   }
}

And a css file "hello-grid.css":

.hello-grid {
    display: grid !important;
    grid-template-rows: auto;
    grid-template-columns: 1fr 1fr;
}

.label-one {
    grid-column: 1;
}

.label-two {
    grid-column: 2;
}

  • How can I associate the ".hello-grid" css class with the HelloGrid Composite.
  • Is this the right/preferred way to use a css grid in Vaadin 12 at all

解决方案

It's a bit too late, but maybe answers someone else question.

It depends where exactly you have placed your css styles. I would suggest to place under webapp\frontend\styles, then you would be able to access them using @StyleSheet("frontend://styles/hello-grid.css"). As it also noted in official documentation, here Including Style Sheets it's

Relative to Servlet URL

Using your example with this set-up:

and styles like those (basically just adding colors to your stylesheet to verify, it works )

this was the output:

I haven't found any exact guides on Vaadin page, how you could use Grid styles, but this tutorial looks quite promising A Complete Guide to Grid. Otherwise, there shouldn't be anything special regarding Vaadin.

Also, it seems that there is an add-on in directory, which might help Css Grid Layout (Through, I haven't tried it out myself)

这篇关于如何在Vaadin Flow中使用CSS网格替代Framework 8的GridLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆