伪元素不显示背景图像

Pseudo element not showing background-image

为什么我的背景图像在伪元素::before 中不显示?我还测试了用背景颜色替换背景图像,但它仍然不起作用。这是 SASS 格式,以防有些人想知道嵌套的 ::before.

.logoframe{
      float: left;
      height: 817px;
      width: 20%;
      position: relative;
      left: -6%;
      transform: skewX(-11deg);
      border: 1px solid #e26f6f;
      &::before{
        content: "";
        background-image: url('/images/theseven/seven_img_old.png');
        background-repeat: no-repeat;
        position: relative;
        height: 817px;
        width: 150px;
      }
    }
<div class="logoframe"></div>

the "display" property. display is CSS's most important property for controlling layout. Every element has a default display value depending on what type of element it is. The default for most elements is usually block or inline . A block element is often called a block-level element.

   &::before{
        content: "";
        display: block;/*missing prop*/
        background-image: url('/images/theseven/seven_img_old.png');
        background-repeat: no-repeat;
        position: relative;
        height: 817px;
        width: 150px;
    }

您应该更新以下 css 部分。如果您需要居中的背景图片,请更新背景位置。

.logoframe{
      float: left;
      height: 817px;
      width: 20%;
      position: relative;
      left: 0;
      transform: skewX(-11deg);
      border: 1px solid #e26f6f;
    }
  .logoframe:before {
        content: "";
        background: url('https://n2.sdlcdn.com/imgs/a/a/1/Chromozome_Yamaha_102025_m_1_2x-4ab77.jpg') 0 0 no-repeat;/* replace 0 0 to center center */
        background-repeat: no-repeat;
        position: absolute;
        background-size:contain;
        top:0;
        left:0;
        height: 817px;
        width: 100%;
      }
<div class="logoframe"></div>

我不知道这是否有帮助,但有时如果您使用背景的快捷方式 属性 它可能不起作用,但如果您使用不同的属性,我认为它可能会起作用。我是根据经验说的。

.showcase::before {
  content: '';
  background-image: url(../images/Desert.jpg) no-repeat center center/cover;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: -1;
}

但这一个做到了。

.showcase::before {
  content: '';
  background-image: url(../images/Desert.jpg);
  position: absolute;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: -1;
}
Sometimes you need to add background-size property too with display: block.

&::before{
        content: "";
        background-image: url('/images/theseven/seven_img_old.png');
        background-repeat: no-repeat;
        background-size:100%;
        position: relative;
        height: 817px;
        width: 150px;
        display:block;
      }