Closed hoshikitsunoda closed 4 years ago
You just have a styling issue. Everything is working as expected with gatsby image.
When using fluid images, they will stretch to fill the container. The container is defined by the content within it but because you're using fluid widths, it's got nothing to guide it.
If you add text below you should see that the image will appear above because it now has some guiding content to use.
To fix this, you can set the article to have a min-width: 100%
so that the content is always filling the container, even if there's no text, but the image still acts fluidly.
@danspratling Thank you for the reply!
I added min-width: 100%
to article element but no image shown:( Tested on both live site and gatsby serve
The article tag is not even including the styling at all.
Just checked your repo.
It looks like you weren't including the plugin in the gatsby-config.js
file
If you add in gatsby-plugin-styled-components
to the list of plugins it should work as you were expecting.
Oh wow, it works now! Thank you so much for your help @danspratling !!
I'm curious why it only affected this image wrapper element though? styled components
was working on all other elements.
I'm not entirely sure. My guess would be that gatsby is doing something in the build phase which means that some components are being pre-generated (using gatsby-config.js) and styled components isn't being used at this point (after all, it just ends up as css in the end). Maybe styled(Button)
is generated differently to styled.button
.
This is just a guess though. I don't know the inner workings of gatsby or styled-components well enough to say anything for certain about the specific reasons behind this problem.
Glad it's working now though!
Description
Hi everyone,
I set up a gatsby blog site using blog starter and hooked it up to Netlify CMS. I am having an issue with displaying images on the index page.
When the page first loads, none of the images on index page would show. If I navigate to other pages and come back to the index, it all appears. It is happening on live site and works fine in dev environment. All images are being sent from CMS as markdown file.
I followed an instruction on here: https://github.com/gatsbyjs/gatsby/issues/3545 and ran
yarn add git://github.com/lfittl/hast-to-hyperscript
but it didn’t fix:(I have asked this in Netlify community but was told to open an issue here since this is a bug on Gatsby side.
Live site:
Dev environment:
Thank you and please let me know if there's anything else I can provide.
Steps to reproduce
Here’s the link to the site: https://hardcore-wiles-235b68.netlify.com
I was able to get images to show up by inserting a style tag to the article element like this:
<article style={{ width:
50%}} key={node.fields.slug}>...</article>
but if I use styled components:
the styling gets ignored and image and wrapping div width is set to 0. Also, jlengstorf at Netlify community pointed out that Gatsby is adding
aria-hidden
attributes and not respecting the height/width.I have ran
gatsby build
andgatsby serve
to serve it locally but no images showed on first load.Repo for this project: https://github.com/hoshikitsunoda/blog-gatsby-netlifycms
Expected result
It should show all the images when the page loads.
Actual result
No images are shown. Image data is there but the dimension is set to 0x0.
Environment
Update(02-03-2020): I swapped the element from
article
to regulardiv
styled withstyled components
, still no image shown.