Webflow sync, pageviews & more.
NEW

How can I vertically center a child container in a section that fills the remaining viewport after the navbar, which reduces the section height?

TL;DR
  • Set the section height to calc(100vh - [navbar height]) using custom CSS or the Style panel.
  • Apply flexbox to the section with vertical direction and center alignment to vertically center the child container.

To vertically center a child container in a section that fills the remaining viewport after the navbar, you need to account for the navbar height and then use flexbox for centering.

1. Set Section Height to Fill Remaining Viewport

  • Use Custom CSS or Webflow’s built-in tools to calculate the section height.
  • If your navbar has a fixed height (e.g. 80px), set the section’s height to calc(100vh - 80px):
  • Add a custom height to the section using the Style panel.
  • In the Height field, enter calc(100vh - 80px).
  • If your navbar is not fixed and flows in the layout, you can set the section’s min-height to 100vh and rely on layout stacking.

2. Enable Flexbox on the Section

  • Select your Section.
  • In the Style panel, go to Layout and set Display: Flex.
  • Choose these flex settings:
  • Flex Direction: Vertical (Column)
  • Justify: Center
  • Align: Center (if you also want horizontal centering)

3. Ensure the Child Container Doesn’t Break Layout

  • Make sure the child element:
  • Doesn’t have fixed or excessive height.
  • Is not pushed by margins/padding that exceed the section height.
  • Set the child’s margin and padding accordingly for responsive behavior.

4. Optional: Use Webflow Spacer Divs If Needed

  • If using calc() isn’t desirable, you can use a top margin or spacer div to visually offset the child element—but this is less dynamic and not recommended for responsive layouts.

Summary

Set the section’s height to calc(100vh - [navbar height]), apply flexbox centering, and make sure your child container is dimensioned appropriately. This ensures vertical centering within a dynamic section height.

Rate this answer

Other Webflow Questions