Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
盖茨比图像:如何将处理后的图像导入css并与背景图像属性一起使用_Css_Graphql_Gatsby - Fatal编程技术网

盖茨比图像:如何将处理后的图像导入css并与背景图像属性一起使用

盖茨比图像:如何将处理后的图像导入css并与背景图像属性一起使用,css,graphql,gatsby,Css,Graphql,Gatsby,我成功地将盖茨比映像实现到我的项目中,并替换了我的组件中使用的许多img标记。但是现在我试图为我的一些组件优化背景图像,但我不知道如何使用盖茨比图像将生成一个新的img标记,我不能使用它作为背景样式,例如div元素。s1可以告诉我如何使用css生成的图像。这是我的密码: const HeaderlineSection = ({headerOne}) => { return( <div className="header-back" ></div> )

我成功地将盖茨比映像实现到我的项目中,并替换了我的组件中使用的许多img标记。但是现在我试图为我的一些组件优化背景图像,但我不知道如何使用盖茨比图像将生成一个新的img标记,我不能使用它作为背景样式,例如div元素。s1可以告诉我如何使用css生成的图像。这是我的密码:

const HeaderlineSection = ({headerOne}) => {
  return(
    <div className="header-back" ></div>
  )
}

export const query = graphql`
  query IndexPageQuery {
    headerOne: imageSharp(id: { regex: "/header_one.jpg/" }) {
      sizes(maxWidth: 1200 ) {
        ...GatsbyImageSharpSizes
      }
    }
  }
我正在使用插件。以下是如何使用它的一个示例:

import React from 'react'
import { graphql, StaticQuery } from 'gatsby'
import styled from 'styled-components'

import BackgroundImage from 'gatsby-background-image'

const BackgroundSection = ({ className }) => (
    <StaticQuery query={graphql`
      query {
        desktop: file(relativePath: { eq: "seamless-bg-desktop.jpg" }) {
          childImageSharp {
            fluid(quality: 100, maxWidth: 4160) {
              ...GatsbyImageSharpFluid_withWebp
            }
          }
        }
      }
    `}
     render={data => {

       const imageData = data.desktop.childImageSharp.fluid
       return (
          <BackgroundImage Tag="section"
                           className={className}
                           fluid={imageData}
                           backgroundColor={`#040e18`}
          >
            <h1>Hello gatsby-background-image</h1>
          </BackgroundImage>
       )
     }
     }
    />
)

const StyledBackgroundSection = styled(BackgroundSection)`
  width: 100%;
  background-repeat: repeat-y;
`

export default StyledBackgroundSection
从“React”导入React
从“gatsby”导入{graphql,StaticQuery}
从“样式化组件”导入样式化
从“盖茨比背景图像”导入背景图像
const BackgroundSection=({className})=>(
{
const imageData=data.desktop.childImageSharp.fluid
返回(
你好,盖茨比背景图片
)
}
}
/>
)
const StyledBackgroundSection=styled(BackgroundSection)`
宽度:100%;
背景重复:重复-y;
`
导出默认样式BackgroundSection
代码是不言自明的,但基本上,元素将替换为在
标记中选择的元素,并将背景图像设置为通过graphql imageSharp查询选择的元素。

这可能会对您有所帮助
import React from 'react'
import { graphql, StaticQuery } from 'gatsby'
import styled from 'styled-components'

import BackgroundImage from 'gatsby-background-image'

const BackgroundSection = ({ className }) => (
    <StaticQuery query={graphql`
      query {
        desktop: file(relativePath: { eq: "seamless-bg-desktop.jpg" }) {
          childImageSharp {
            fluid(quality: 100, maxWidth: 4160) {
              ...GatsbyImageSharpFluid_withWebp
            }
          }
        }
      }
    `}
     render={data => {

       const imageData = data.desktop.childImageSharp.fluid
       return (
          <BackgroundImage Tag="section"
                           className={className}
                           fluid={imageData}
                           backgroundColor={`#040e18`}
          >
            <h1>Hello gatsby-background-image</h1>
          </BackgroundImage>
       )
     }
     }
    />
)

const StyledBackgroundSection = styled(BackgroundSection)`
  width: 100%;
  background-repeat: repeat-y;
`

export default StyledBackgroundSection