I need help. I'm a complete beginner and I can't find solution anywhere, so sorry if it was already asked, but no matter what I tried I couldn't display background image on one page.
What I want to do?
Display the background image on home page.
Notes:
Since there was no assets folder in my root, I created one in src folder.
Structure:
► node_modules
▼ src
▼ app
▼ components
▼ home
home.component.html
home.component.scss
home.component.spec.ts
home.component.ts
▼ assets
▼ images
▼ bg.jpg
.angular-cli.json
"assets": [
"assets",
"images",
"favicon.ico"
],
home.component.scss
.homeBg {
background-image: url('../../../assets/images/bg.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
width: 100vw;
height: 100vh;
}
Can someone please help me and tell me what I did wrong? I'm losing my mind for almost 3 hours trying to figure this out.
Thanks in advance.
By default, a background-image is repeated both vertically and horizontally. Tip: The background image is placed according to the background-position property. If no background-position is specified, the image is always placed at the element's top left corner.
The background-repeat CSS property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.
CSS background-repeat By default, the background-image property repeats an image both horizontally and vertically.
The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element.
Solved here.
This is because you've also specified "no-repeat" along with your background image. Alter your code to:
background: url('../../../assets/images/bg.jpg') no-repeat center center fixed;
Thanks @Mike Lun for reminding me to check the actual error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With