Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda