# [Tutorial] Getting rid of the empty space at the top of the MainUI Overview (and keeping an embedded floor plan flush)

For a long time my Overview page had an annoying gap at the very top, both in the Android app and in the browser.
The first thing on the page is my floor plan, and it never started right below the header. There was always a strip of nothing first, which costs precious space on a phone. I tried the usual tips from the forum: setting --f7-navbar-height: 0, putting a .block:first-child { margin-top: 0 } stylesheet on the block, hiding the navbar. The gap shrank a little at best, or just moved somewhere else. Others asked the same question over the years (here,
here and here), but no answer was marked as working. I finally tracked it down. The space comes from several independent sources, so fixing only one of them never looked like a real improvement.

Before / after (Android app, Overview as the home page tab):

TL;DR

On the page that shows the gap (here the Overview), remove the navbar and the top margin of the first block. Set the margin as a style, not in a stylesheet:

config:
  hideNavbar: true
  style:
    --f7-block-padding-horizontal: 0px    # optional: no side padding
blocks:
  - component: oh-block
    config:
      style:
        margin-top: 0px                   # on the first block itself
    slots:
      default:
        - ...

If your page embeds another MainUI page in a frame (oh-webframe-card, e.g. a floor plan page), also add this to the embedded page:

config:
  hideNavbar: true
  style:
    --f7-navbar-height: 0px               # the unit matters

With both changes, the first card on my Overview starts 10 px below the top, which is just the card’s own margin. On a regular layout page with navbar it starts at 106 px.

Tested on openHAB 5.1.4 in Chromium, Firefox and the openHAB Android app.

What is actually going on

1. The stylesheet trick can’t work

The most common suggestion is this:

- component: oh-block
  config:
    stylesheet: |
      .block:first-child { margin-top: 0; }

It looks right, but it does nothing, and the reason is easy to miss. MainUI scopes component stylesheets. When the component is mounted, every rule in its stylesheet gets the component’s own unique class as a prefix, so the browser actually sees

.scoped-abc123 .block:first-child { margin-top: 0; }

That selector matches elements inside the block, never the block itself. The block keeps its margin.

The fix is to skip the stylesheet and set the value in style:, which MainUI applies directly to the element. This is a general rule: use a component’s stylesheet for its children and its style for the component itself.

2. --f7-navbar-height: 0 is not what it seems

Framework7 uses this variable inside calc(), e.g. calc(var(--f7-safe-area-top) + var(--f7-navbar-height)). In calc() you can’t add a plain number to a length. With 0 (or 0.0, which the page editor likes to write) the whole expression becomes invalid and the browser silently drops it. Write 0px.

On the Overview itself you usually don’t need the variable at all. hideNavbar: true removes the navbar and its padding. Where the variable really matters is the next point.

3. An embedded page brings its own gap

My floor plan is a separate plan page that the Overview shows in an oh-webframe-card. Even with hideNavbar: true, the plan page positions its map with

.oh-plan-page-lmap { top: calc(var(--f7-safe-area-top) + var(--f7-navbar-height)); }

So the map is pushed down by one navbar height inside the frame. From the outside this looks exactly like empty space at the top of the Overview, which is why fiddling with the Overview never fully removed it. The fix belongs on the embedded page: --f7-navbar-height: 0px in its page style.

If your Overview doesn’t embed anything, points 1 and 2 are all you need. If it uses a custom widget, padding inside the widget (e.g. on its main container) is part of the widget’s own code and has to be changed there.

Bonus: a floor plan that fills its frame exactly

Once the gap on top was gone, I noticed a second, smaller problem: a letterbox around the plan, sometimes at the sides, sometimes at the bottom. That is Leaflet, which the plan page uses internally:

  • It only zooms in steps of 0.1 (zoomSnap). Scale = 2^zoom, so the plan is almost never exactly as wide as your card.
  • It never zooms out below −2 (minZoom), which matters on small phones.
  • It fits the image once, when the page loads. If the frame changes size later, the plan keeps the old zoom.

The trick is to make the frame exactly as large as the zoom step Leaflet is going to pick:

zoom  = max(floor(log2(availableWidth / imageWidth) * 10) / 10, -2)
frame = ceil(imageWidth * 2^zoom) + 1   x   ceil(imageHeight * 2^zoom) + 1

You can compute that in MainUI expressions from screen.appWidth. Two details make it reliable:

  • Add the computed width to the frame URL (/page/<uid>?w=<width>). Whenever the width changes, the iframe reloads and Leaflet fits again.
  • Give the iframe 16 px of slack (16 px larger, moved back with margin: -8px, and the card crops it). In Chromium a scrollbar can appear for a moment inside the frame while it loads. Leaflet then measures a slightly smaller frame and chooses the next lower zoom step.

Pitfalls I hit on the way

  • oh-grid-col renders only its first child. Wrap several cards in an f7-block.
  • An oh-repeater placed directly in an oh-grid-row is not expanded (TypeError: can't access property … of undefined). Put it inside an f7-block.
  • A space before = (" =items.X.state") quietly turns an expression into plain text. This happens easily when editing widget props.
  • screen.viewAreaWidth reported a too large value in the Android app. Math.min(screen.appWidth, screen.viewAreaWidth || screen.appWidth) is safe.

I hope this saves someone the evenings I spent on it. Questions and corrections are welcome.

Thanks for bringing all this together.

Just for completeness, you should actually be able to use the stylesheet for this. Everything you’ve said about scoping is correct, but there’s an additional selector option that I don’t think is documented yet (and it really should be more well-known). The CSS host pseudo selector is translated in these specific instances as applying to the element that is defining the stylesheet. So, in your example:

- component: oh-block
  config:
    stylesheet: |
      :host:first-child { margin-top: 0; }

should achieve your desired css results. Using the style object is, in my opinion, usually the clearer way to go in these instances, but this can make a big difference in specific situations.