I am trying to make the background image display on .hero, which means the image will be at the center of the page, but the image doesn’t display at all. In "devtools", it shows a warning sign next to the image.
I tried to put the image on the body and eliminate the position absolute that I put in the CSS; however, it didn’t affect the results. Please help. I thought the position absolute might push other elements like the .hero class, which has the background image. I also tried writing it in several ways with ” and with two dots and even with one dot.
.hero {
background-image: url("https://picsum.photos/100/100") center center/cover
no-repeat;
margin-top: 8rem;
padding: 11.5rem 2rem 8rem;
position: relative;
overflow-x: hidden;
}
<header class="hero">
<div class="container-heroflex">
<div class="hero-content">
<h1>Create your own video courses</h1>
<p>
dive deep into the world of creativity and learn to craft stunning
videos that captivate your audience
</p>
<a href="#" class="btn">29$ Get Course</a>
</div>
<div class="hero-img">
<img src="https://picsum.photos/300/300" alt="header-course" />
</div>
</div>
</header>
3
Answers
You need to separate background-image the position, size, and repeat in different line.
Quoting from CSS background docs
Simply use the
background
property instead ofbackground-image
like this:You can try using this code:
}
I hope this helps you.