How can I overlay text on an image in Webflow while maintaining the same dimensions as the image for hover effects?

TL;DR
  • Place the image and text inside a relatively positioned container.  
  • Use an absolutely positioned overlay div with Flexbox to center text and match image dimensions.  
  • Set initial overlay opacity to 0 and adjust it with smooth transitions on hover without changing element sizes.

To overlay text on an image in Webflow and ensure the overlay matches the image dimensions (especially for hover effects), follow these structured steps.

1. Set Up the Parent Container

  • Add a Div Block to act as the image container.
  • Give it a class name, e.g., ImageWrapper.
  • Set the position to relative so child elements (like the image and overlay text) can be absolutely positioned.
  • Set fixed dimensions, or let the image define them if it's responsive.

2. Add the Image

  • Inside ImageWrapperdrag in an Image Element.
  • Set the width to 100%, height to auto (or a fixed height if required).
  • If needed, set the image’s z-index to 1 to ensure it sits below the overlay.

3. Add the Text Overlay

  • Still inside ImageWrapperadd another Div Block for the text overlay (e.g., OverlayText).
  • Set the overlay’s position to absolute, and top/left/right/bottom all to 0.
  • This makes it perfectly overlap the image.
  • Use Flexbox (on OverlayText):
  • Set display to Flexjustify and align center to center the text.
  • Add a Text Block or Heading inside this overlay div.
  • Style your text (e.g., white text, large font size, slight shadow).

4. Add Hover Effect

  • Select the ImageWrapper and go to the Hover state.
  • Add desired effects:
  • For example, change overlay background color, increase text opacity, or scale the image slightly.
  • Make sure the overlay is initially hidden or semi-transparent (e.g., opacity: 0) and becomes visible on hover (opacity: 1).
  • Apply transitions (e.g., ease-in-out for 300ms) for smooth animation.

5. Maintain Same Dimensions on Hover

  • Because the overlay is absolutely positioned within a relatively positioned parent (ImageWrapper), it will always match the parent's dimensions.
  • Do not modify height/width of child elements on hover as that could cause layout shift.

Summary

To overlay text on an image in Webflow and keep it perfectly aligned for hover effects, use a relatively positioned container with an absolutely positioned overlay div. Use Flexbox for centering text and manage hover states and opacity for effects without disturbing dimensions.

Rate this answer

Other Webflow Questions