[英]Set complete background for Angular project
I tried many times and searched a lot about how to set image background for whole app in angular project.我尝试了很多次并搜索了很多关于如何在 angular 项目中为整个应用程序设置图像背景的信息。
I tried global css and app.component.css but it just set background for component area.我尝试了全局 css 和 app.component.css 但它只是为组件区域设置了背景。
Here is my global css file:这是我的全局 css 文件:
body {
font-family: 'Vazir';
background-image: url("assets/back.jpg");
background-repeat: repeat-y;
background-position: center;
background-size: cover;
}
I defined another css file and link in index.html but it didn't work well.I have also set directly into body tag in index.html but I got same result.我定义了另一个 css 文件并在 index.html 中链接,但效果不佳。我还直接在 index.html 中设置了正文标签,但我得到了相同的结果。
PS: I don't want to set pixels or percentage in css file. PS:我不想在 css 文件中设置像素或百分比。
Thanks in advance提前致谢
You can achieve it in the following way:您可以通过以下方式实现它:
1-Define a router outlet in the root component (probably app.component.html) 1-在根组件中定义一个路由器出口(可能是app.component.html)
<div class="outlet-wrapper">
<router-outlet></router-outlet>
</div>
2- In the relative style file (app.component.css/scss), define: 2- 在相关样式文件 (app.component.css/scss) 中,定义:
.outlet-wrapper {
background-image: url("assets/back.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.