admin管理员组

文章数量:1278721

I have a page, served with Nuxt SSR. It has a header with position:fixed and content that will have a padding-top that equals the header's height:

.content {
    padding-top: var(--header-height);
}

Before I switched to using SSR I simply set the custom CSS var in the onMounted hook of the header component. This would come too late now, since the content will already be rendered before the Vue app mounts (SSR).

Is there an elegant way to set the custom CSS variable --header-height (i.e. on the <html> tag) before the page content is rendered? Could I somehow do the following?

  1. Retrieve the header height server-side
  2. Inject a script to the document's head that sets the variable on the <html> element, using the value from 1.

本文标签: vuejs3Nuxt Set custom CSS Var asapdepending on height of elementStack Overflow