I have created a simple default page that gets rendered with content (images and text) from GraphCMS.
I can query and display the content, but I'm not sure how to make the images adjust to the view/container, as I don't know how to access the image and set a CSS class.
I'm using the plugin "gatsby-plugin-mdx" to render the following: page.content.markdownNode.childMdx.body
Here is my DefaultPage.tsx file:
import React from "react"
import Layout from "../layout/layout"
import styled from "styled-components"
import { H1, BodyMain } from "../styles/TextStyles"
import { MDXRenderer } from "gatsby-plugin-mdx"
export default function DefaultPageTemplate({ pageContext: { page } }) {
return (
<Layout>
<Wrapper>
<HeaderWrapper>
<TextWrapper>
<TitleWrapper>{page.title}</TitleWrapper>
<SubtitleWrapper>{page.subtitle}</SubtitleWrapper>
</TextWrapper>
</HeaderWrapper>
<ContentWrapper>
<MDXRenderer>{page.content.markdownNode.childMdx.body}</MDXRenderer>
</ContentWrapper>
</Wrapper>
</Layout>
)
}
const Wrapper = styled.div``
const HeaderWrapper = styled.div`
min-height: 300px;
color: #ffffff;
background-color: #339861;
display: grid;
justify-content: center;
align-items: center;
padding: 30px;
`
const TextWrapper = styled.div`
text-align: center;
`
const TitleWrapper = styled(H1)``
const SubtitleWrapper = styled(BodyMain)``
const ContentWrapper = styled.div`
margin: 1rem;
`
Below is a screenshot of the behaviour:
Below is a screenshot of when I'm inspecting the element in the browser. It appears that the image is wrapped in a paragraph:
Can you help me to understand how to scale the image for smaller views/screens?