Created
November 15, 2018 10:40
-
-
Save smakosh/a236073a68db6fb4d4b6654865d27935 to your computer and use it in GitHub Desktop.
Gatsby-image as a background image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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