简体   繁体   English

正在平铺的背景图像

[英]Background image being tiled

I have this image being pulled from a url:我从 url 中提取了这张图片:

在此处输入图像描述


And I'm using the following code to display it as background, inside my component render() :我在我的组件render()中使用以下代码将其显示为背景:

Field.jsx字段.jsx

const { players } = this.props;

return (
  <div className="back" style ={ { backgroundImage: "url('https://url.svg')" } }>
      <div className="field-wrapper" >
         <Output output={this.props.strategy} />
           <div className="row"> {this.getPlayersByPosition(players, 5).map((player,i) => (
               <Position key={i}>{player.name}</Position>))} 
           </div>
 </div>
)

What am I missing?我错过了什么?

But the image is being tiled, like so:但是图像正在平铺,如下所示:

在此处输入图像描述

This is Field.css :这是Field.css

.back {
  display: flex;
  justify-content: center;
  text-align: center;
  align-items: center;
  height: 100vh;
  width: 100%;
}

.field-wrapper {
  overflow: hidden;
  width: 400px;
  height: 600px;
}

.field-row {
  display: flex;
  flex-direction: row;
  width: 100%;
}

I think this will help:我认为这会有所帮助:

background-repeat: no-repeat, no-repeat;

you can find more in:您可以在以下位置找到更多信息:

https://www.w3schools.com/cssref/pr_background-repeat.asp https://www.w3schools.com/cssref/pr_background-repeat.asp

I would get rid of the inline style and do something like this:我会摆脱内联样式并做这样的事情:

 .back {
        background: url(pathToYourImg) no-repeat center; 
        -webkit-background-size: cover; 
        -moz-background-size: cover; 
        -o-background-size: cover; 
        background-size: cover;
   } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM