Skip to content

Instantly share code, notes, and snippets.

@smakosh
Created November 15, 2018 10:40
Show Gist options
  • Save smakosh/a236073a68db6fb4d4b6654865d27935 to your computer and use it in GitHub Desktop.
Save smakosh/a236073a68db6fb4d4b6654865d27935 to your computer and use it in GitHub Desktop.
Gatsby-image as a background image
import Img from 'gatsby-image'
import styled from 'styled-components'
import PropTypes from 'prop-types'
export const BgImage = styled(Img)`
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
height: ${({ height }) => height || 'auto'};
& > img {
object-fit: ${({ fit }) => fit || 'cover'} !important;
object-position: ${({ position }) => position || '50% 50%'} !important;
font-family: 'object-fit: ${({ fit }) => fit || 'cover'} !important; object-position: ${({ position }) => position || '50% 50%'} !important;'
}
`
BgImage.propTypes = {
height: PropTypes.string,
fit: PropTypes.string,
position: PropTypes.string
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment