Overlaying images with non-rectangular shapes

I am struggling to achieve a specific design for my bootstrap card. The card is filled with an image and I have placed text on top of it, which is made visible by using a transparent overlay. I would like the overlay to be slanted, similar to the effect seen on the cards on the homepage of .

Here is the HTML structure of my card:

<div class="card border-0" style="width:100%;">
<img class="card-img-top" src="IMAGE HERE" alt="Card image">
<div class="card-img-overlay">
</button>
<div class="bottom text-light">
SOME TEXT OVER IMAGE HERE
</div>
</div>
</div>

And here are the styles applied to the card:

    .card {
        box-shadow: 1 3px 1px 1 rgba(1, 1, 3, 0.6);
        transition: 0.3s;
        width: 100%;
        border-radius: 15px;
        padding: 3px;
    }

    .card:hover {
        box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.4);
    }

    /* Applying dark filter on card image */
    .card-img-top {
        width: 100%;
        height: 350px;
        object-fit: cover;
        filter: brightness(85%);
        border-radius: 15px;
        padding: 2px;
    }

    /* Aligning heading text to bottom of the photo */
    .bottom {
        position: absolute;
        right: 0;
        left: 0;
        padding: 15px;
        bottom: 0px;
        padding-bottom: 15px;
        background-color: rgba(12, 23, 23, 0.6);

        border-top-left-radius: 0px;
        border-top-right-radius: 0px;
        border-bottom-left-radius: 15px;
        border-bottom-right-radius: 15px;
    }

Answer №1

Here are three techniques to create a slanted container:

  • Apply transform: rotate(); to an element separate from the text container.
  • Utilize pseudo elements ::before or ::after.
  • Use a background-image of a .png file for transparency on the text container.

Pseudo elements ::before and ::after need to be connected to a specific element, such as a div. They must also include the content property in order to display properly.

div::before {
  content: "";
}

These pseudo elements are considered children of the element they are attached to, like the div in this case. This allows for easy positioning using absolute positioning.

I have created a fiddle example with a card design. https://jsfiddle.net/vbgrn98s/1/

You may need to adjust the border-width property to customize the size of the container to your liking.

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

How can you locate the position of a selector within a parent or set using jQuery

Could someone please help me determine the position of the current selector within its parent using jQuery? I need this information in order to effectively use the .insertAfter() and .insertBefore() methods to rearrange elements within their nested structu ...

Delete the option to alter button in the Jasny file input tool

I recently incorporated the Jasny Fileinput Widget into my existing form. However, I noticed that when I select a new file, it displays two buttons: Change and Remove. In this case, I believe the Change button is unnecessary and would like to remove it com ...

Troubleshooting a Vue.js formatting problem in Visual Studio 2019

Encountering an issue with VS2019 while attempting to format this code section. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="milestone.ascx.cs" Inherits="uc.dms.milestone" %> <section class="content-header"> <h1> ...

The list style of Bootstrap Select Drop Down isn't vertical

Has anyone encountered an issue with bootstrap-select where the options in a drop down box are not vertically listed? <script src="{% static 'risk_parity/js/jquery-3.2.1.min.js' %}"></script> <script src="{% static 'r ...

Arranging input fields for different languages

I recently inherited a product that has been developed using AngularJS, and I have a query related to localization. Within the HTML code, there are two input fields of type 'input-number' - one for entering the number of days and another for spe ...

How can images from a dynamic table be converted to base64 format in Vue.js and then sent in a JSON file?

Hello everyone, I'm facing an issue with a dynamic table where I need to add multiple rows, each containing a different image. I attempted to convert these images to base64 format and save them in a JSON file along with the table data. However, the pr ...

Attempting to conceal a div element along with its contents using AngularJS

I am attempting to use AngularJS to hide a div and its contents. I have defined a scope variable initialized as false and passed it to the div in order to hide it. However, the div is still visible along with its content. <script type="text/javascr ...

Is there a way to horizontally align my navigation bar links with CSS while maintaining grey borders on the sides?

What is the best way to center my navigation bar links using CSS without losing the grey sides? Both Blogs and History have dropdown menus. Check out this screenshot: https://i.sstatic.net/2kvTm.png (source: gyazo.com) CSS: .navbar ul { list-styl ...

Updating a post in Vue.js using its unique id

Recently, I delved into the world of vue.js and stumbled upon this intriguing question on Stack Overflow. It provided some valuable insights on how to fetch posts from a database using v-for. Upon loading each post, I noticed the presence of Edit and Dele ...

Looking for a search box that functions like Google's search feature

I am attempting to create a text box similar to the Google search text box... So far, I have implemented a feature where, upon entering a character, words starting with that character are displayed in a div using AJAX. This functionality is working well, ...

Utilizing Bootstrap Containers for Improved Website Design Layouts

I'm a bit puzzled on the usage of Bootstrap's containers. Should I nest the entire body of my webpage within one container and then use rows for each section, or should I use individual containers for each section? For instance, do I do it like ...

Imagine a scenario where clicking on an image causes it to be rotated or

Could use some assistance figuring out what's missing here. I've added a random photo from Wiki, similar in size to the images I'll be working with. The images will vary in size, but I want them to always remain visible within the browser w ...

Troubleshooting problem with jQuery's .has() and .click() functions

I have created a lengthy html code: <div id="el"> <p data-skip>Blablabla</p> // On click, toggle this, and toggle next p <p data-skip>Blablabla</p> // On click, toggle this, and toggle next p <p data-skip>Bl ...

Issue with sticky navbar in parallax design

I have been working on a website where all pages feature a header and a navbar located just below it. As the user scrolls down the page, I want the navbar to stick to the top of the screen once it reaches that position. However, on one specific page, I am ...

In MUI v5 React, the scroll bar vanishes from view when the drawer is open

Currently, I am working on developing a responsive drawer in React using mui v5. In the set-up, the minimum width of the drawer is defined as 600px when it expands to full width. However, an issue arises when the screen exceeds 600px - at this point, the d ...

Include a popover or information button on the title panel of the accordionItem in shiny interface

I have a Shiny application featuring an accordion. I am interested in incorporating a popup message into the title panel, either in the form of an info button or a hovering function! I have experimented with the bs4Dash popover element, but unfortunately ...

Exploring the blur() function in JavaScript through cold calling

There is a specific line of code that I need help with. document.getElementById("firstName").addEventListener("blur", validateField); Additionally, there is this block of code: validateField = (event) => { const el = event.targe ...

Tips for implementing a dynamic value in the ng-style based on certain conditions

Is there a way to set a background-color conditionally using ng-style when the color value can be updated from $scope? These are the variables in my scope: $scope.someone = { id: '1', name: 'John', color: '#42a1cd' }; $scope ...

Issue with submitting form using Jquery on select action

There seems to be an issue with this jquery code that is supposed to trigger a form submit when a drop down select is changed. It works fine on our test site, but once we move it to the live website, it breaks. Can someone help us troubleshoot and identify ...

The problem with the Image Gallery carousel not functioning properly in a right-to-left direction arises when attempting to modify

I have been developing an image gallery that functions perfectly in the English version of the website. Now, I am tasked with replicating the same functionality for another version of the website that requires right-to-left (RTL) direction. However, when I ...