[英]How to set the background of an Angular app to an image?
In my app.component.css I have在我的 app.component.css 我有
.container{
background-image: url(/image.jpg);
}
and in app.component.html I have在 app.component.html 我有
<div class="container">
<h1>image</h1>
</div>
I am confused with this is not working.我对这不起作用感到困惑。 Is there a better way to set a background image for the app?
有没有更好的方法来为应用程序设置背景图像?
Demo you should also set its width and height 演示你还应该设置它的宽度和高度
.container{
background-image: url(/image.jpg);
width:100%;
height:100%;
background-repeat: no-repeat;
background-size: cover;
}
and you also set html and boys width and height too in styles.css你也在styles.css中设置了html和boys的宽度和高度
html,body{
width:100%;
height: 100%;
margin:0 auto;
}
I created a sample on Stackblitz for you我在Stackblitz 上为您创建了一个示例
Try using background
like this:尝试使用这样的
background
:
app.component.css应用组件.css
.img {
background: url(imgage-url-address-here);
height: 480px;
}
app.component.html应用程序组件.html
<p class="img">
Start editing to see some magic happen :)
</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.