Place the Div in a consistent position on images of varying widths

I have a dilemma with my class that is supposed to display images. The issue arises when I try to place a div within an image inside this class.

Everything works smoothly when the image takes up the entire width of the class, but as soon as the image width is reduced, the div shifts and loses its responsiveness :(

Does anyone have any ideas on how to fix this?

Picture Predicament

https://i.stack.imgur.com/qOQC4.png

Image does not fill the width ... causing the div to be misaligned.

Here is My Code ---> Stackblitz

You can view the code snippet above and experiment by changing the image widths.

HTML Markup

 <div class="drop" >
          <div class="abc">
            <img class="img-fluid Images" src="https://i.ibb.co/3p3D4h6/dmitry-bayer-276d-F1-RG67-Q-unsplash.jpg">
        <div class="row boxImage">
            <div class="row divBtn">
                <a class="toggle-one">
                    <span class="nav-link btnZ"></span>
                  </a>
                <a class="toggle-two">
                  <span class="nav-link btnT"></span>
                </a>
                <a class="toggle-three">
                  <span class="nav-link btnR"></span>
                </a>
                <a class="toggle-four">
                  <span class="nav-link btnP"></span>
                </a>
             </div>
          <ul class="list-inline rating-list" *ngFor="let star of stars" style="display: inline-block">
            <li (click)="countStar(star)" [ngClass]="{'selected': (star <= selectedValue)}">
              <i class="fa fa-star"></i>
            </li>
          </ul>
        </div>
          </div>
        </div>

CSS Styling

.drop {
    margin-left: 25px;
    width: 90%;
    height: 696px;
    border-radius: 15px;
    overflow: hidden;
    text-align: center;
    background: white;
    position: relative;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

      .boxImage{
        cursor: pointer;
        position: absolute;
        background-color: white;
        background-position: 13px 13px;
        background-repeat: no-repeat;
        height: 50px;
        width: 44%;
        border-radius: 8px;
        opacity: 1;
        top: 91%;
        left: 43%;
      }

   .abc {
    height: 100%;
}



.abc img {
    height: 100%;
    max-width: 100%;
}

Answer №1

Utilize flex and max-width to create a responsive design.

  .boxImage {
        flex: 1 1 100%;
        cursor: pointer;
        position: absolute;
        background-color: white;
        background-position: 13px 13px;
        background-repeat: no-repeat;
        height: 50px;
        width: 44%;
        border-radius: 8px;
        opacity: 1;
        top: 91%;
        left: 43%;
        max-width: 250px;
      }

Check out the live demo here - https://stackblitz.com/edit/angular-rkz7zh

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

Trouble with displaying my three.js 3D model

I've tried multiple solutions I found, but none have fixed the issue of not being able to display 3D models. Many have suggested that it could be a problem with the camera, but so far I haven't been able to resolve it. Any assistance would be gre ...

Set the background color of the container row to extend the full width, encompassing

I am working on a grid container and I want to change the background color of the second row within it. Check out my Fiddle This is the HTML markup: <div class="totalContainer totalContainer__space"> <div class="totalContainer__ ...

Restrain a Key according to the data type of its value within a universal category

I am currently working on creating a versatile function where the generic type is used to define its parameter. Here's an excerpt from this parameter : type Configuration<T> = { masterdata: T[], target: ???? } I am encountering difficu ...

Tips for setting a specific height for an HTML table

For some reason, I can't seem to control the height of this table. I've set it to a maximum of 20px but all the rows are still showing. Here is the CSS: table { border:1px solid black; overflow:hidden; height:20px; max-height:20 ...

Can we store an API response in cache to access the API without an internet connection?

Is there a way to cache the master date API so that even when offline, the response can still be accessed? ...

Is the `document.documentElement` consistently defined and always representing the HTML element?

I am looking to make changes to the <html> element using a script within the <head> section of an HTML page. My goal is to only access and modify the <html> element itself, without affecting any of its children. Should I wait for the DOM ...

Unexpected background image slideshow appearance

I am encountering an issue with my slideshow where the last image briefly appears before the first image loads in a continuous loop. The offset of the initial image causes it to start at the middle of the window, and in Google Chrome and Safari, subsequent ...

The angular core module is displaying an inaccurate peer dependency warning regarding zone.js

Encountered this error message when trying to update my Angular version: @angular/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e88b879a8da8d9d8c6d9c6dd">[email protected]</a>" has an incorrect peer dependency ...

How can I prevent the content from sliding out of view in a Bootstrap carousel?

I am looking to create a slider that includes a form or text. However, I have noticed that when scaling up by 50-75% or when there is a lot of content, the content extends beyond the slider. Image Check out my code on jsfiddle: jsfiddle.net/sL70r2an/ ...

What is the method to determine the encoding that the user is using to input into the browser?

After reading Joel's insightful article about character sets, I have decided to follow his advice by using UTF-8 on both my web page and in my database. However, one thing that confuses me is how to handle user input. As Joel aptly points out, "It doe ...

Discover the name of a color using its HEX code or RGB values

Is there a way to retrieve the color name from RBG or HEX code using JavaScript or JQuery? Take for instance: Color Name RGB black #000000 white #FFFFFF red #FF0000 green #008000 ...

The border of the cell in the top row only partially overlaps with the margin area

Have you noticed how the left border of the first cell doesn't line up with the margin area of the table? This peculiar phenomenon seems to occur only in the first row: https://i.stack.imgur.com/qMWCh.jpg In all other rows, the border aligns proper ...

"Encountering a Cypress Angular error: CypressError with the message 'Timed out retrying: Expected content was not

During my Cypress test run, I encountered an error message on the last step (click) which stated: Timed out retrying: Expected to find element: .button-darkblue, but never found it. Here is the code snippet: describe('Test Login', () => { i ...

Tips on concealing all classes except one through touch swiping

If you have a website with a single large article divided into multiple sections categorized as Title, Book1, Book2, & Book3, and you want to implement a swipe functionality where only one section is displayed at a time, you may encounter some issues. ...

How to detect a click event in any area of an Angular2

Hey there, I'm new to typescript and angular 2 and I've encountered an error in my code. Can someone lend me a hand in fixing this? import { Component, HostListener } from '@angular/core' export class TooltipComponent { public sh ...

An additional "?" symbol found in the PHP file at the top left corner

I am experiencing an issue with a PHP page where a "?>" symbol appears in the top left corner. The code snippet looks like this: <?php include_once("DBconnect.php"); $getuser = $_POST["RegUsername"]; $getpass = $_POST["Pass"]; $getrepass = $_POST[" ...

Radio buttons may not appear initially upon loading the first page

Can anyone explain why the radio buttons are not visible when the page first loads? I am using Angular Material's mat-radio-buttons. Click here for the code ...

Substitute using JQuery

Hello, I am attempting to update some html using Jquery, here is my current progress. $(".old").html($(".new").html()); It's almost working. The problem is that the .new content is being copied instead of replaced. I want to Cut/Paste instead of Co ...

Unusual problem arises with scoping when employing typeguards

Consider the following TypeScript code snippet: interface A { bar: string; } const isA = <T>(obj: T): obj is T & A => { obj['bar'] = 'world'; return true; } let obj = { foo: 'hello' }; if (!isA(obj)) thro ...

Typescript's way of mocking fetch for testing purposes

I have a query regarding the following code snippet: import useCountry from './useCountry'; import { renderHook } from '@testing-library/react-hooks'; import { enableFetchMocks } from 'jest-fetch-mock'; enableFetchMocks(); i ...