如何在div中设置图片样式?

所以我开店,我想对图像进行样式化。 现在我在div中看不到面孔:

webshop

我知道这是小事,但我无法实现:

菜单项组件:

从“反应”导入React; 导入“ ./menu-item.styles.scss”;

const MenuItem = ({ title, imageUrl, size }) => (
  <div className={`${size} menu-item`}>
    <div
      className="img"
      style={{
        backgroundImage: `url(${imageUrl})`
      }}
    />
    <div className="content">
      <h1 className="title">{title}</h1>
    </div>
  </div>
);

export default MenuItem;

菜单项样式:

    .menu-item {
  min-width: 30%;
  height: 240px;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid black;
  margin: 0 7.5px 10px;
  border-radius: 10px;

  .img {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center center;
    position: relative;
    right: 0px;
    border-radius: 10px;
  }

  &:hover {
    .title {
      transition: ease-in 0.6s;
      opacity: 1;
      cursor: pointer;
    }
  }

  &.small-sneakers {
    background-position: center;
  }

  &.large {
    height: 420px;
  }

  &:first-child {
    margin-right: 7.5px;
  }

  &:last-child {
    margin-left: 7.5px;
  }
  .content {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
  }

  .title {
    font-weight: bold;
    margin-bottom: 6px;
    font-size: 22px;
    color: white;
    text-transform: uppercase;
    align-items: center;
    opacity: 0;
    z-index: 3;
    position: absolute;
  }
}

当我尝试做背景位置:顶部-50px中心时,则图像无响应:/

谢谢您的帮助!

评论