In Bootstrap cards, image overlays are always displayed on top of the image

I'm struggling to understand why I can't get the image in this HTML snippet to appear anywhere other than on top. Despite my attempts to adjust z-index, use !important overrides, and try other methods for hours, I haven't been successful. My suspicion is that this issue may be related to how bootstrap handles cards.

My ideal layout would have a solid background at the 'bottom' of the stack, followed by the background image, and then the actual overlay content. While it would be convenient to separate these into divs, I'm unsure if this is compatible with bootstrap cards. At this point, I am open to any solution as long as the background image does not end up on top.

Check out the bottom image for the current output.

  • Current behavior: (from bottom to top) (solid background -> content -> background image)
  • Desired behavior: (from bottom to top) (solid background -> background image -> content)

For context, I am running flask with a template that utilizes this code as a snippet. The snippet is 'called' three times to create the grid displayed in the image. As far as I can tell, this should provide all the necessary information to pinpoint the issue. If not, I am willing to update this post with more details.



<div class="card">

  <div style="opacity:{{category['opacity']}}; z-index: 0">
    {% if category['image'] is not none %}
    <img src={{category['image']}} class="card-img-overlay" style="object-fit: cover; height: 100%; width: 100%; padding: 0%;">
    {% endif %}
  </div>

  <div class="card-body" style="z-index: 1 !important; background-color: {{category['color']}}; color: black;">
  <div >

  </div>
    <div style='z-index: 5 !important;'>
      <br><br><br>
      <a href={{category['url']}} class="stretched-link"></a>
      <h3 class="card-title text-center">{{category['name']}}</h3>
      <hr style="border-color: white;">
      <p class="card-text text-center font-weight-bold">{{category['description']}}</p>
      <br><br><br>
      <!-- <ul class="list-group">
        <li class="list-group-item">url: {{category['url']}}</li>
        <li class="list-group-item">img: {{category['image']}}</li>
      </ul> -->
    </div>

  </div> 
</div>

snippet output

Answer №1

After much troubleshooting, I finally found the solution to achieving the desired behavior as described below:

<div class="card bg-dark text-white">
  <div style="background-color: {{category['color']}};">
    <div style="opacity:{{category['opacity']}};">
      {% if category['image'] is not none %}
      <img class="card-img" src={{category['image']}} alt="" style="object-fit: cover; height: 100%; width: 100%; padding: 0%;">
      {% endif %}
    </div>
    <div class="card-img-overlay text-center">
      <a href={{category['url']}} class="stretched-link"></a>
      <h3 class="card-title text-center">{{category['name']}}</h3>
      <hr style="border-color: white;">
      <p class="card-text text-center font-weight-bold">{{category['description']}}</p>
    </div>
  </div>
</div>

desired end result

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for positioning HTML elements at the exact mouse location as it moves, without any delay?

Currently, I am in the process of developing a web-based drawing application that does not rely on using a canvas. My decision to avoid using a canvas is because I plan to incorporate CSS Keyframes into the HTML elements upon placement. This approach allow ...

What is the best way to save high-resolution images created with HTML5 canvas?

Currently, there is a JavaScript script being used to load and manipulate images using the fabricjs library. The canvas dimensions are set to 600x350 pixels. When smaller images are uploaded onto the canvas and saved as a file on disk, everything works c ...

Issues arise when attempting to implement a basic quiz using jQuery or JavaScript

I’ve created a quick quiz to determine how many correct answers a person gets when they click the 'submit' button. However, it keeps showing zero as the result. Can someone please assist me? $(document).ready(function(){ $('button' ...

The navigation icon on my website refuses to close

Hey there, I'm having some trouble creating a side navigation menu. The issue I am facing is that the menu opens without any problem, but then I can't seem to figure out how to close it using a second "onclick()" function. If you could take a lo ...

JavaScript to enable button functionality for selected items

Currently, I am developing a To-Do List application. Once users input information, it gets displayed in a table format. My objective is to have the ability to select specific items from this table and apply various button functionalities to them such as ma ...

The video player will only start playing after the source has been changed if it was already in play

I am facing an issue with my video player that has thumbnails. The problem is that the video player does not start playing the selected video unless the video is already playing. This means I have to hit the play button first, and then select the thumbnail ...

Flask - Refreshing Forms Dynamically

In an effort to enhance the responsiveness of my app, I am looking for a way to prevent the page from reloading every time a POST request is sent. My current setup includes a dynamically generated form with input fields designed like this: <div class=&q ...

Adjust the floated item's width when it is moved downwards

I have two divs positioned side by side. The first div is 600px wide and the second is 200px wide, with some spacing in between. Both divs are floated to the left so that if the window size is reduced, the second div will move below the first. My goal is ...

Expanding SVG Button Overlay in ChakraUI

I am trying to design a uniquely shaped button that sits on top of an image, but I am encountering some challenges with the scaling of the button mask. Both the image and masks were created at the same base dimensions for easy alignment at 0,0. Here is a ...

Get hexa values from a colorpicker and use them as a background in an angularjs application

I'm currently working on an angularJS project and I've implemented an HTML color picker. My goal is to assign the selected color from the color picker to my div element, ensuring that the values are in hexadecimal format. Below is a snippet of my ...

Combining various types of media stylesheets with a print stylesheet

I'm struggling with a school assignment that is asking me to compare two different ways of linking a print stylesheet with another stylesheet in HTML. The assignment requires me to explain when each technique would be appropriate: <link rel="style ...

Validation is only effective for the initial row and fails to apply to subsequent rows. This may be due to the necessity of including the return true/false statement in my validation process

HTML PHP <div align="center"><input type="text" class="form-control" id="<?php echo $i;?>" name="r2<?php echo $i+1;?>" onblur="mvalidate2()" style="text-align: center; bo ...

The Angular8 form encounters an error when trying to access the 'valid' property of an undefined value

I am implementing a register form to add an employee and including validation for accuracy. However, I encountered an error message that reads "cannot read property of 'valid' of undefined." Here is the code snippet: HTML <div class="conta ...

CSS animation: Final position once the vertical text has finished scrolling

I have designed a CSS-animated headline with a leading word and three vertically-scrolling/fading statements to complete the sentence, inspired by the style used on careers.google.com. The animation runs through three cycles and stops, leaving the third st ...

How can I receive user input in JavaScript while incorporating three.js?

I am currently exploring the functionalities of this three.js example () and I am interested in enabling users to input specified X, Y, and Z positions for boxes dynamically. Initially, I considered utilizing a JavaScript prompt like below: var boxes = p ...

Incorporating Font Awesome into your gulp project the right way

Looking for advice on incorporating Font Awesome into a new gulp-scss-bootstrap project. What is the proper and efficient method to do so? Thanks in advance! ...

Can the CSS of an iframe be modified if the iframe is located on a different domain?

Is it feasible to modify the CSS of an iframe if the iframe is not located on the same domain? If so, what are some ways to apply and alter CSS for this situation? Any assistance would be greatly appreciated. <iframe id="frame1" width="100%" height="35 ...

Is there a way to remove a checkbox node that has already been generated?

I've been working on creating a to-do list, and I've run into an issue with deleting the checkbox once the task is complete. I attempted to create a function within the main function containing an if/else statement, but it didn't seem to wo ...

Steps for Sending Data Using a URL

I am having trouble deleting a row based on its id. Below is the code I am using: <tr> <th>ID</th> <th>Nom etudiant</th> <th>Prenom etudiant</th> ...

I am unsure of the best method to position this using flex in Bootstrap 5

Introduction to Bootstrap 5 Challenge: Greetings! I am currently exploring Bootstrap 5 after a hiatus of two years, and I have encountered a problem. Despite reviewing the documentation on the official Bootstrap 5 website, I am unable to position the new c ...