我正在尝试将图像放在boostrap卡的标头中,我确实知道还有其他类似问题,但是我认真尝试了一切。
代码如下:
<div class="container">
<div style="padding: 20px 0px;" *ngFor="let blog of blogs">
<div class="card">
<div class="card-header" (click)="navigate('Blog')">
<a (click)="navigate(blog.title)">{{ blog.title }}</a>
</div>
<div class="card-body">
<p class="card-text">
{{ blog.summary }}
</p>
</div>
</div>
</div>
</div>
css:
.card-header {
background: rgba(0, 255, 0, 0.61);
color: rgb(0, 0, 0);
font-weight: bold;
cursor: pointer;
}
.card-body {
background: #43484d;
}
.card-text {
color: #6cffce;
font-weight: bold;
}
我尝试过
background-image: url(imagepath)
它不起作用 我也尝试过
<image src ...>
为顶部重叠,但两者都不是
我只想将图片放在标题中,该图片将是透明的,顶部带有一种颜色(有点像看玻璃一样的东西)
答案 0 :(得分:1)
根据您的要求,这是您的代码,请参见代码卡标题,您可以将其应用在任何可以正常工作的地方。这是链接codepen link here
<div class="container">
<div style="padding: 20px 0px;" *ngFor="let blog of blogs">
<div class="card">
<div class="card-header" (click)="navigate('Blog')">
<a (click)="navigate(blog.title)">link</a>
</div>
<div class="card-body">
<p class="card-text">
Para1
</p>
</div>
</div>
</div>
</div>
CSS在这里...
html, body {
height: 100%;
width: 100%;
margin: 0;
color: #f9f0f3;
background: #D21237;
}
.card-header {
background: rgba(0, 255, 0, 0.61);
color: rgb(0, 0, 0);
font-weight: bold;
cursor: pointer;
position:relative;
height:10vh;
}
.card-header::before{
content:"";
background-image: url("http://www.hdnicewallpapers.com/Walls/Big/Abstract/Red_and_Blue_Smoke_Creative_Design_Wallpaper.jpg");
height:10vh;
position: absolute;
top:0px;
width:100%;
z-index:99999;
}
.card-body {
background: #43484d;
}
.card-text {
color: #6cffce;
font-weight: bold;
}
答案 1 :(得分:1)
不确定您想要什么。检查此代码段是否有任何想法。
.card-header {
background: linear-gradient(rgba(255, 0, 0, 0.25), rgba(255, 0, 0, 0.25)), url(http://www.tedgoas.com/assets/images/work/stack-overflow/cover.jpg) no-repeat center center;
height: 200px;
position: relative;
}
.card-header a {
color: white;
font-weight: bold;
font-size: 50px;
position: absolute;
top: 40%;
left: 40%;
}
.card-body {
background: #43484d;
}
.card-text {
color: #6cffce;
font-weight: bold;
}
<div class="container">
<div>
<div class="card">
<div class="card-header">
<a>Header</a>
</div>
<div class="card-body">
<p class="card-text">
Body
</p>
</div>
</div>
</div>
</div>