0

我从网址中提取了这张图片:

在此处输入图像描述


我正在使用以下代码在我的组件内将其显示为背景render()

字段.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>
)

我错过了什么?

但是图像正在平铺,如下所示:

在此处输入图像描述

这是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%;
}
4

2 回答 2

0

我认为这会有所帮助:

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

您可以在以下位置找到更多信息:

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

于 2020-09-22T03:05:47.350 回答
0

我会摆脱内联样式并执行以下操作:

 .back {
        background: url(pathToYourImg) no-repeat center; 
        -webkit-background-size: cover; 
        -moz-background-size: cover; 
        -o-background-size: cover; 
        background-size: cover;
   } 
于 2020-09-22T03:07:48.390 回答