简体   繁体   中英

Image doesn't show up in div

I want to give my component a full page background image, but the image doesn't show up. When i check the developer console, all the css is good.

import React from "react";
import "./about.styles.scss";


const AboutPage = () => {
  return (
    <div className="about">
      <div className="background-image">
        <div className="aboutText">Some text</div>
      </div>
    </div>
  );
};

export default AboutPage;

CSS:

.background-image {
  background: url("https://i.ibb.co/TYpKc61/bg.jpg");
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  text-align: center;

  position: relative;
  width: 100%;
  height: 100%;

  text-align: center;


  .aboutText {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 5rem;
  }
}

Any idea how to solve this problem?

You need to give the container with className="about" some dimensions so the relative dimensions styles of background-image will be applied (like width: 100%; ).

.about {
  height: 100vh;
  width: 100vw;
}

.background-image {
  width: 100%;
  height: 100%;

  ...
}

编辑 nice-christian-urih7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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