0

I am trying to put a image inside a header in a boostrap card, I do know there are other questions like this but I seriously tried everything.

Here is the code:

<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;
}

I have tried

background-image: url(imagepath)

it does not work I also tried

<image src ...>

as top-overlay but that neither

I just want to put an image in the header which will be transparent with on the top a color (kind of like looking into a glass type of thing)

Card

Brain Bytes
  • 121
  • 1
  • 12

2 Answers2

1

Here is your code as per your requirement see the code card-header same thing you can apply in anywhere it will work fine. here is link 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 goes here...

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;
}
codeuix
  • 1,366
  • 1
  • 12
  • 18
1

not exactly sure what you want. check this snippet if it gives you any ideas.

.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>
kcsujeet
  • 465
  • 2
  • 8
  • you can also change the blend mode with `background-blend-mode` property if you want. – kcsujeet Jul 02 '19 at 04:57
  • yeah works well, the problem now is how to make angular assign dynamically an id and then put it in, as every card head should look different – Brain Bytes Jul 05 '19 at 01:41
  • check this https://stackoverflow.com/questions/37575368/angular-dynamic-background-images – kcsujeet Jul 05 '19 at 11:59
  • yeah that does not work, I tried to sanitize too, but not, this is what I tried to put in just to see if the image shows up [ngStyle]="'url(blog.imagePreview)'" if I just do [style.background]=" 'url(http://www.tedgoas.com/assets/images/work/stack-overflow/cover.jpg)' " this works I tried also this [style.background]=" 'url('blog.imagePreview')' " – Brain Bytes Jul 06 '19 at 22:30
  • Nvm, it works, silly me! Thank you so much, you are my hero dude! – Brain Bytes Jul 06 '19 at 22:42