What is the best way to position a span overlay on a card in the lower right corner

I am looking to add a thumbnail with the duration displayed in the bottom right corner of a video, but I am facing issues moving the span object within the card using Bootstrap 4. Whenever I try to increase the margin-left beyond 50%, the span object crashes:

<!DOCTYPE html>
<html lang="en>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  <style>
  .duration {
background-color: black;
color: white;
padding-left: 4px;
padding-right: 4px;
opacity: 0.7;
border-radius: 5px;
}
    
    .card-img-overlay {
    position: absolute;
    margin-top: 75% !important;
        margin-left: 51% !important;
        margin-right: 0% !important;
    }
  </style>
</head>
<body>
 
<div class="container-fluid">
  <div class="card img-fluid mt-2" style="width:200px">
    <img class="card-img-top" src="https://www.w3schools.com/bootstrap4/img_avatar1.png" alt="Card image" style="width:100%">
    <div class="card-body">
      <p class="card-text">Example text here</p>
    </div>
    <div class="card-img-overlay">
      <span class="duration">2:42:42</span>
    </div>
  </div>
</div>

</body>
</html>

EDIT: I managed to resolve this issue by updating the CSS in the following way:

.duration {
    background-color: black;
    color: white;
    padding-left: 4px;
    padding-right: 4px;
    opacity: 0.7;
    border-radius: 5px;
    position: absolute;
    top:65%;
    left:68%;
}

Answer №1

If you're looking to customize the padding property within the class card-img-overlay, you can do so by setting an override. Here's a suggestion to try:

.card-img-overlay {
    position: absolute;
    margin-top: 85% !important;
    margin-left: 68% !important;
    margin-right: 0% !important;
    padding: 0;
}

I hope this helps, buddy.

Answer №2

You also have the option to align it to the right.

align:right;

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

Issue with child div exceeding 100% height within CSS Flexbox causing inconsistency in Firefox and Chrome browsers

I am facing a challenge trying to make a div resize to match its parent's height using flexbox. This issue seems to occur only in Chrome (48), as it displays correctly in Firefox (44). You can view the example on Fiddle: https://jsfiddle.net/jvilla/k ...

Creating a three-column layout in HTML5 with resizable left and center columns, and a fixed right column

Looking to create a full screen layout with three columns, where the left/center column is resizable and the right column remains fixed. Currently using the resize style for the left area, but running into issues as the center area does not adjust in size ...

Creating grids and dividing them using a combination of CSS, JavaScript, and PHP

I've encountered an interesting challenge while working on a web project and would love some advice on how to tackle it: Within a database, I have a collection of images that I want to display in a grid format. The twist is that higher ranked images ...

Switching an :active class using ReactJS

Currently, I am working on creating an onboarding screen where the user is required to select three or more items. Once the user clicks on an item, a purple overlay should remain visible. For reference, this is what I have in mind: https://i.sstatic.net/ ...

Align two spans within a div using the margin auto property

I often find myself struggling with the basics, it seems like I can't figure this out. I want the two spans to be centered within the div with auto margins... https://jsfiddle.net/5k4pnmf7/ <div class='foo'> <span class='bar& ...

What could be causing my title (titulo) to be misaligned? Why aren't justify and align functions fixing the issue?

My attempt to center my title "Scream" is not working as expected. Here is how it looks: Visit this link for visualization. I have tried using justify, align, and text-align properties in my CSS code but the title (titulo) remains misaligned. Surprisingly ...

Inadequate text alignment

Trying to create a header mockup for a website featuring branding elements like a logo and brand name. Utilizing Angular.js for the webpage development process, incorporating a URL for the logo image from an online source. Encountering alignment issues th ...

Creating CSS dynamically using PHP

Even after reading numerous blogs and forums, I'm still unable to get this working. My goal is to allow users to personalize their user account style sheet. I made sure to include <?php header("Content-type: text/css"); ?> at the beginning of t ...

Use the jQuery library to detect scrolling and toggle the CSS class between 'selected' and

I am trying to dynamically add the "selected" class to a[href] when a specific DIV comes into view while scrolling. However, I want to remove this class completely once the DIV has been scrolled past. const links = $(".cd-faq-categories li a"); // Find al ...

What is the best way to achieve a set number of columns at certain breakpoints?

Is there a way to implement the following layout using Bootstrap 4? Displaying 4 columns on a large breakpoint; 3 columns on a medium breakpoint; and 1 column on a small breakpoint. Below is my current code snippet: <html> <head> ...

What is the best way to position a div on top of another within a container using Bootstrap?

I have created a div with a date picker inside a form for future fields, but the initial display is next to the table instead of above it. I've searched for solutions similar to my issue, but none seem to work for me. You can view the correct layout ...

Having troubles with Navbar svg images not loading on certain pages on the express/ejs app?

Hello there, I'm encountering an issue with my navbar in an express app. The navbar is saved as a partial and included in a boilerplate wrapper used on most pages. Here's a snippet of how it looks: <h1>HELLO<h1> Within the boilerplat ...

Having trouble loading image on web application

Currently, I am facing an issue while attempting to add a background image to an element within my Angular web application. Strangely enough, the relative path leading to the image seems to be causing my entire app to break. https://i.stack.imgur.com/b9qJ ...

When I access the website through the LinkedIn app, my CSS styles are getting jumbled up

Is there a way to resolve the problem I'm facing with CSS when accessing the site through the LinkedIn app on iPhone? The issues don't occur on Android. If anyone has a solution, please share. Thank you :) Click Here ...

CSS dropline menu

I am working on customizing a CSS dropdown menu for my website. My goal is to have the homepage aligned to the left side of the page instead of the center. Below is the style sheet and the div tags I am using for the dropdown navigation bar: ul, li, htm ...

Designing a menu header against a specific background color resulting in misalignment

I have been working on creating a menu header for my website. If you would like to take a look, here is the link to my jsfiddle page. Unfortunately, I am facing an issue where all my images and text should remain in that grey color scheme but somehow it& ...

Move divs that are currently not visible on the screen to a new position using CSS animations

Upon entering the site, I would like certain divs to animate from an offscreen position. I came across this code snippet: $( document ).ready(function() { $('.box-wrapper').each(function(index, element) { setTimeout(function(){ ...

Steps for aligning an image to the right using Bootstrap Vue

I'm currently learning Bootstrap Vue and I'm trying to align an image on the right using a b-card header. The challenge I'm facing is that when I add the image, it disrupts the perfect size of the template header, causing the image to show a ...

Alter the style of a div by clicking on a button

Can the background image of a div be changed by selecting a button outside of the div? For example: HTML <div id="change"></div> <div id="buttons"> <button class="button1">this</button> <button class="button2"> ...

Ways to modify the header color of a card by utilizing a Select element in Javascript, while ensuring that it does not impact other cards

I am facing an issue with multiple cards, each containing a Select element. When a user selects an option from the Select element, the card header changes color, but it also affects all other card headers. How can I separate them? [data-background-co ...