Flexbox issue

  • Platform information:
    • OS: Win11
    • Java Runtime Environment: 21.0.9
    • openHAB version: 5.2.3

Hello,

I consider myself a beginner with OH. For a few days, I’ve been trying to solve an issue that’s driving me crazy. I simply want to have columns with the same height. Without using min-height or other workarounds.

This is simple (standard) HTML:

<html>
<head>
	<style>
		.col-container {
		  display: flex;
		}
		.col {
		  flex-grow: 1;
		  margin: 0;
		  padding: 10px;
		}
	</style>
</head>

<body>
	<div class="col-container">
	  <div class="col" style="background:orange">
		<p>Column 1</p>
	  </div>

	  <div class="col" style="background:green">
		<p>Column 2</p>
		<p>Hello World!</p>
	  </div>

	  <div class="col" style="background:yellow">
		<p>Column 3</p>
	  </div>
	</div>
</body>
</html>

and here is what I get:

image

Trying to simulate this on the main page (Overview) using code:

version: 1
pages:
  page_2445414a10:
    tags: []
    props:
      parameters: []
      parameterGroups: []
    component: oh-layout-page
    config:
      label: prova
    slots:
      canvas: []
      default:
        - component: oh-block
          config: {}
          slots:
            default:
              - component: oh-grid-row
                config:
                  style:
                    display: flex
                slots:
                  default:
                    - component: oh-grid-col
                      config:
                        style:
                          background-color: orange
                          flex-grow: 1
                      slots:
                        default:
                          - component: oh-label-card
                            config:
                              label: Column 1
                    - component: oh-grid-col
                      config:
                        style:
                          background-color: green
                      slots:
                        default:
                          - component: oh-card
                            slots:
                              content:
                                - component: oh-label-card
                                  config:
                                    label: Column 2
                                - component: oh-label-card
                                  config:
                                    label: Hello World!
                    - component: oh-grid-col
                      config:
                        style:
                          background-color: yellow
                      slots:
                        default:
                          - component: oh-label-card
                            config:
                              label: Column 3
      grid: []
      masonry: []

getting this:

I’ve tried every possible combination and option related to flexbox, but with no result.

So I copied the code and pasted it into a new widget (which is easier for me to use): the moment I replaced oh-row with div, everything magically fell into place.

version: 1
widgets:
  zzz:
    tags: []
    props:
      parameterGroups: []
    component: f7-block
    slots:
      default:
        - component: div
          config:
            style:
              display: flex
          slots:
            default:
              - component: div
                config:
                  style:
                    background-color: orange
                    flex-grow: 1
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        label: Column 1
              - component: div
                config:
                  style:
                    background-color: green
                    flex-grow: 1
                slots:
                  default:
                    - component: oh-card
                      slots:
                        content:
                          - component: oh-label-card
                            config:
                              label: Column 2
                          - component: oh-label-card
                            config:
                              label: Hello World!
              - component: div
                config:
                  style:
                    background-color: yellow
                    flex-grow: 1
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        label: Column 3

I cannot figure out what is causing this behavior. The generated code confirms that the container (class=“row no-gap”) is a flexbox:

Any suggestions? Thanks

Alberto

This does not surprise me at all. By the time you get to the level of the oh-grid columns and rows there are several layers of interference between you and basic html elements. The f7 library that oh components are mostly built from has a TON of it’s own CSS and any time you run into a css issue like this there’s a 9 in 10 chance that the problem is a conflict between what you are trying to do and that f7 styling (which can frequently have !important directives just to make it even harder on you).

In this case, that row class (which comes from the f7 library) might be your issue. It sets align-items to flex-start and you want normal or stretch. I don’t remember off the top of my head if the grid columns over-ride that under any circumstances, but my first try would be to add align-items: stretch to the row style.

First of all, thanks for the tip! I had already tried every possible way. But the wrong one.

Wrong way 1:

              - component: oh-grid-row
                config:
                  style:
                    display: flex
                    align-items: stretch

style is ignored

Wrong way 2:

              - component: oh-grid-row
                config:
                  class:
                    - display-flex
                    - align-items-stretch

As before, the class is ignored

Working mode:

              - component: oh-grid-row
                config:
                  stylesheet: |
                    .row { align-items: stretch }

As a new OH user, I’d like to add that the issue with OH is precisely the uncertainty regarding when, what, and how to use a given component. Those who started back with version 1 don’t have this problem. I’ve only just begun, so I need to adapt myself :wink:

This gets into some of the real nitty-gritty of how the MainUI is built with vue and the original assumptions that went into the design. Some of the components, like these grid components were never really conceived of as things that the users would need that much fine control over. This built-in grid system is really supposed to be the low-code, beginner gets decent looking UI with a few clicks kind of arrangement. So, the oh-grid-row and oh-grid-column don’t actually pass the yaml defined class array on to the underlying elements. If you’re comfortable looking through vue files, when you get stuck like this you can always quick check the vue source pages to see. If not, trial and error testing is pretty quick and definitive.

If you haven’t gone through this series yet, it might help (sorry it’s a little long winded). You already appear to know much of what’s in the first one and the third one, but there may be some extra tidbits that help organize the widget components for you.