Card design with title displayed in a translucent overlay over the image using Bootstrap

I am trying to design a bootstrap card that features the title in a semi-transparent box positioned over the image, while keeping the rest of the card in line with the standard bootstrap design. The code I have written so far is as follows:

<style>
.box{
    position: relative;
}
.box .text{
    position: absolute;
    z-index: 999;
    margin: 0 auto;
    left: 0;
    right: 0;        
    text-align: center;
    align-items: center;
    justify-content: center;
    top: 40%;
    background: rgba(178, 0, 0, 0.8);
    font-family: Arial, sans-serif;
    color: #fff;
    width: 100%;
    height: 10%;
}
</style>
<div class="container">
        <div class="card img-fluid" style="width:500px">
            <img class="card-img-top" src="img/green.jpg" alt="Card image" style="width:100%">
            <div class="card-img-overlay box">
                <h4 class="card-title text">Title</h4>
            </div>
            <p class="card-text">Some example text some example text. Some example text some example text. Some example text some example text. Some example text some example text.</p>
            <a href="#" class="btn btn-danger">Learn more</a>
        </div>
    </div>

Here is what it looks like currently: https://i.sstatic.net/auId8.jpg

The issue I am facing with my code is that the red box containing the card title does not adjust responsively. It covers not just the image, but the entire card. How can I modify it so that the red box appears at the bottom of the image? I have tried adjusting the css "top" and adding "bottom", but since the text extends beyond the image, it does not work properly.

I want the final outcome to resemble this design: https://i.sstatic.net/blIga.jpg

The red box holding the card title should always remain at the bottom of the image, regardless of screen size.

UPDATE

This is how it appears after implementing the additional code below.

https://i.sstatic.net/zu2iP.png

Answer №1

Rearrange the .card-img-overlay element to be positioned over the image and title as demonstrated below:

<div class="card-img-overlay box">
    <img class="card-img-top" src="img/green.jpg" alt="Card image" style="width:100%">
    <h4 class="card-title text">Title</h4>
</div>
       

Then, apply the following CSS styling to the title:

.box {
    position: relative;
}
.box .text {
    position: absolute;
    z-index: 999;     
    text-align: center;
    bottom: 0;
    left: 0;
    background: rgba(178, 0, 0, 0.8);
    font-family: Arial,sans-serif;
    color: #fff;
    width: 100%; /* Set the width of the positioned div */
    height: 10%;
}

This configuration should achieve the desired outcome

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

Adjust the navigation bar to expand based on the amount of content it contains

I have two pages for my website - a forum and a homepage. While the homepage is all set up, I need to make some modifications to the navigation bar on the forum page. I have mirrored the navigation bar from the homepage to the forum to ensure consistent st ...

Tips for making a scrollable container that allows its contents to overflow without clipping?

Currently working on implementing a horizontal card row for my website with a unique hover effect - the cards lightly rotate and raise on hover. Here is a preview: https://i.sstatic.net/eDQ59.gif To make this row responsive, I added overflow-x: auto; to e ...

Reset all divs to their default state except for the one that is currently active using jQuery

Here's the plan for my script: Once a user clicks on a "learn more" button, it will reveal the relevant information in the corresponding box. I'm aiming to implement a feature where if you click on another "learn more" button while one box is a ...

The $(window).load(function() function is unable to run once the entire document has finished loading

I have not been able to find the solution in the following circumstances: In an HTML document, I successfully load multiple other HTML files. However, within one of these included HTML files, specifically "navmenu.html," I want to execute a script with a ...

What could be causing the sudden disappearance of the button?

There is an element with the ID "alpha" that contains the text "Now I'm here...". When the button is clicked, only the text should be removed, not the button itself. <div id="alpha">Now I'm here...</div> <button type="button" oncl ...

What is the reason for having two elements positioned just 50 pixels apart, with the top element having a margin-bottom of 50px and the bottom element having a margin-top of 50px

I have encountered a strange issue while trying to ensure that two elements remain consistently 100 pixels apart in my code. Despite having no errors, the margin-bottom on the P tag is set to 50 pixels and the margin-top on a DIV below it is also set to 50 ...

Why does my JavaScript code only function properly on the initial div element?

I want to create a JavaScript function that changes the color of the title when I hover over an image. It seems to be working, but only for the first div. Could it be an issue with my scoping? Thank you! <body> <div> <a href="" i ...

After resetting my computer, I am now encountering an error message that states "There is no 'Access-Control-Allow-Origin' header present". Why is this happening?

After reformatting my pc, I encountered a new issue when sending an ajax request which involved calling a php file. The message displayed was: "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' ...

Optimal method for storing text descriptions across two platforms (react native and react)

Hello, I hope you are doing well. I have a question regarding two platforms that I am using - React Native and React (NextJS). Both platforms have forms to save data, one of which is a "text description." Here's the issue: When I input a long passag ...

Discovering whether a link has been clicked on in a Gmail email can be done by following these steps

I am currently creating an email for a marketing campaign. In this email, there will be a button for users to "save the date" of the upcoming event. I would like to implement a feature that can detect if the email was opened in Gmail after the button is cl ...

Guide to implementing a personalized CSS rule within Ionic 3 using an SCSS file

I have set up a header within an ion-card, where I am displaying a logo. Initially, everything was working well with inline CSS styling. However, to improve organization, I decided to move the styles to a .scss file. Unfortunately, after doing so, the styl ...

Tips for changing text color using JavaScript when hovering the mouse?

I am working on a website for a snow cone stand and am looking to add a unique effect to their flavor list. I want to create an interactive experience where hovering over a flavor name scales the text and changes its color to match the real fruit. Is the ...

Searching for a way to sort out role-specific usernames in a dropdown menu using AngularJS?

Is there a way to effectively filter usernames based on specific roles in a dropdown using AngularJS? Hello, I am trying to filter the usernames with the 'KP' role in the dropdown list. Please refer to My plunker for more information. Init ...

numerous requirements for formatting utilizing Css modules

Can someone help me figure out how to set multiple conditions using a ternary operator to style an element with Css modules? I'm struggling to find the right syntax. Is it even possible? import style from './styles.module.sass' const Slider ...

Is it possible to center without specifying a fixed width?

Check out this demo link Is there a way to center all the divs and paragraphs under the main div without specifying a fixed width value? I want to remove the 300px width in the .center class and have all the elements align center. Specifically, how can I ...

Implement the map function to validate every input and generate a border around inputs that are deemed invalid or empty upon button click

Currently, I'm in the process of developing a form with multiple steps. At each step, when the next button is clicked, I need to validate the active step page using the map function. My goal is to utilize the map function to validate every input and ...

How can I insert an image into a circular shape using HTML and CSS?

To achieve the desired effect, the image should be placed inside a circle with a white background. The image size should be smaller than the circle and centered within it. One possible way to accomplish this is: .icon i { color: #fff; width: 40px; ...

Why are my menu and title shifting as I adjust the page size?

I'm having trouble finalizing my menu and headings. Whenever I resize the browser window, they shift to the right instead of staying centered as I want them to. I would really appreciate any help with this. Below is the HTML and CSS code. var slide ...

What is the best approach for Angular directives: utilizing a single object or separate values as attributes?

This question pertains to best practices, but I do believe there is a definitive answer. I have a directive that offers six customizable options. Should I assign each option to a separate attribute on the directive (as shown below): <my-directive my ...

Experiencing difficulties with JavaScript/jQuery when encountering the 'use strict' error

I have been working on a small function to change the background of an HTML file, but I keep getting the 'Missing 'use strict' statement' error message from JSLint despite trying multiple solutions. Can anyone suggest how to resolve th ...