Closed SammyIsra closed 5 years ago
does it work when switching fluid={sharpPhoto.childImageSharp.fixed}
into fluid={sharpPhoto.childImageSharp.fluid}
we use something called flex embed to make sure we keep ratio in tact
padding-bottom is nan because you're using fixed instead of fluid.
That does help in that the images seen in the page inspector no longer have a width or height of 0px, and the padding-bottom is no longer NaN:
However, the images still do not show, visible here: https://deploy-preview-10--optimistic-goodall-a71eb1.netlify.com/photographer (same link as before)
Any solutions to this? I'm having the same problem.
Well, for one you're wrapping the images in an anchor tag element, and making them inline-block. I can't recall specifics but just using a block instead of inline-block appears to fix the issue. Presumably because width/height isn't defined for the inline-block(anchor tag), so if it's width is 0px, then 100% of that for any elements within(the gatsby image), that's correct?, alternatively specify a width value for the anchor element and it'll also work.
If you don't want to use a fixed value since you're using flex in the parent element as display, set a child to something like flex: 1;
or flex-grow: 1
etc.
The solution that worked for me was wrapping each anchor tag in a div which is assigned a width of 100%: Then, flexbox is applied to the div instead of the anchor tag:
import Img from 'gatsby-image'
const ImgGallery = ({ data }) => (
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<div style={{ width: '100%' }}>
<a href='#'>
<Img fluid={data.fluidImageOne.childImageSharp.fluid} />
</a>
</div>
<div style={{ width: '100%' }}>
<a href='#'>
<Img fluid={data.fluidImageTwo.childImageSharp.fluid} />
</a>
</div>
<div style={{ width: '100%' }}>
<a href='#'>
<Img fluid={data.fluidImageThree.childImageSharp.fluid} />
</a>
</div>
</div>
)
I looked properly at your code @SammyIsra sadly what you want isn't really feasible as you want it. Fluid will always keep it's ratio so you probably want to move into a masonry view. Or go for fixed and keep it centered.
I think that makes sense. In any case, I switched the style of what I was trying to do, thank you!
using fixed worked for my case, but I'm not sure WHY exactly :P
In case this helps, check if your CSS has any unscoped instances of position: relative
.
Something like this will easily break gatsby-image:
* {
position: relative;
}
Just in case someone's looking for a way to restrict the image size to max its original size (Not sure if it's the best approach, but it worked to me). In the query, you might want to add the original img size like this:
query {
logoImg: file(relativePath: { eq: "logo.png" }) {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
original {
width
}
}
}
}
And then you can just use it in the element wrapping the image to set its width
Set the parent that wraps the image to flexGrow: 1 Here a material UI example:
imageGrid: {
flexGrow: 1,
}
<Grid item sm={6} className={classes.imageGrid}>
<Img fluid={mainImage.fluid} alt="Cruise ship" />
</Grid>
Summary
fluid
images seem to have no width or height on a flexbox display.Relevant information
I've tried using
fixed
images as well, but these images need to shrink when the width of the display is smaller.A demonstration can be seen here: https://deploy-preview-10--optimistic-goodall-a71eb1.netlify.com/photographer right under the description, there is a flexbox display of images where all the images are too small to be seen.
The code for where I use
gatsby-image
is here: https://github.com/SammyIsra/SammyPortfoliov2/blob/1d26c04a049eed718b866baa51870523837e9e68/src/pages/photographer.js#L117Environment (if relevant)
Also: Mozilla Firefox v65
File contents (if changed)
gatsby-config.js
:package.json
:gatsby-node.js
:gatsby-browser.js
: N/Agatsby-ssr.js
: N/A