Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
How can I add an overlay over a Gatsby Static Image Component?

Hey it's my first time posting and I am a pretty new web developer.

I am trying to use Gatsby static image component to show an image and then overlay that image with a div element to write over the picture. I am using a styled component to with position absolute, however, that div isn't going over my picture but instead going to my foooter component.

Down the line, once I get the basic layout of my page done, then I will transfer the images to my sanity cms to host the images and query the images with graphql.

This is what I have so far:

import React from "react"
import styled from "styled-components"
import { StaticImage } from "gatsby-plugin-image";

const StyledHome = styled.div`
  display: flex;
  gap: 2rem;
  position: absolute;
  flex-direction: row;
  margin: 2rem 0;
`;

const HomeTextContainer = styled.div`
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  width: 100%;
  height: 50%;

`;

export default function IndexPage()  {
  return (
    <>
    <StaticImage
        src="../images/picturesWeb.png"
        alt="Website Example"
        placeholder="traceSVG"
        layout="fullWidth"
       />
    <StyledHome>
      
        <h2>Hello</h2>
  
      
    </StyledHome> 
    </>
  )
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

What is happening is that your absolute positioned element is relative to the parent, in this case, the parent is the body (or the <div id="__gatsby">) so it's appearing from the bottom of the page. It has nothing to do with Gatsby/React, it would happen the same using standard HTML.

What you need to do, is to wrap the whole set inside a relative element, so the absolute fading-in element will be positioned relative to that.

import React from "react"
import styled from "styled-components"
import { StaticImage } from "gatsby-plugin-image";

const StyledHome = styled.div`
  display: flex;
  gap: 2rem;
  position: absolute;
  flex-direction: row;
  margin: 2rem 0;
`;

const HomeTextContainer = styled.div`
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  width: 100%;
  height: 50%;
`;

const RelativeElement = styled.div`
  position: relative;
`

export default function IndexPage()  {
  return (
    <RelativeElement>
    <StaticImage
        src="../images/picturesWeb.png"
        alt="Website Example"
        placeholder="traceSVG"
        layout="fullWidth"
       />
    <StyledHome>
        <h2>Hello</h2>
    </StyledHome> 
    </RelativeElement>
  )
}

There's a lack of containers and wrappers but get the idea and tweak it as you wish.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!