Adjusting the position of an element when the width of its parent div shifts

Struggling with the challenge of absolute and relative positioning in CSS. My GUI allows users to view folders and select how many columns they appear in, as shown in the images provided. Beneath each folder is an input field for renaming and a clear button.

The issue arises when the width of the columns changes, causing the absolute positioning of the clear button to misalign. See examples here: Picture 1 - correctly positioned; Picture 2 - misaligned button.

<div ng-class="colStyle" ng-repeat="folder in getFolders(currentFolder)">                               
    <input type="image" ng-src="{{folder.img}}" ng-click="enter(folder)"/>                              
    <div ng-show="showFont && editing" class="testing">
        <input type="text" ng-model="folder.name"/>                                     
        <img class="clearName" src="img/clear.png" ng-click='clearName($index, folder)'/>                               
    </div>                              
</div>

My HTML code uses "colStyle" from responsivegridsystem.com to define the number of columns displayed. Relevant CSS classes are "testing" and "clearName":

.testing{
    position: relative;
    margin: 0px;
    padding: 0px;
}
.clearName{
    position: absolute;
    left : 80%;
    top: 5px;
}

The problem lies in setting the absolute position of the clear button based on column changes. How can I ensure it remains consistent regardless of the number of columns chosen?

Answer №1

Why not start styling from the right of the input field?

Imagine you want to position the clear button 5px from the right side, you can achieve this with the following CSS:

.clearName{
 position: absolute;
 right: 5px;
 top: 5px;
}

This method assumes that the input box spans the full width of the outer div.

The use of percentages in this case is dynamic because it adjusts based on the width of the outer div (100px => 80% => 20px and 200px => 80% => 40px).

If you don't want to make the input field span the width of the outer div (.testing), you can reverse the approach by making the outer div (.testing) match the width of the input field.

To do this, you can apply the following CSS:

.testing {
  display: table;
  margin: auto;
}

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

Using AngularJS to handle error validation for dropdowns and select elements that will redirect using the ng

Currently, I am utilizing angularjs's ng-href along with a select HTML element containing ng-model. The ng-href is being used to link to the "selectedItem" from ng-model. However, I have encountered difficulty in validating or displaying an error mess ...

"Upon clicking the submit button, no action is triggered and no _POST values are being received

When a user clicks on my submit button, nothing seems to happen. The HTML code for the button is as follows: <td colspan="3"> <div align="center"> <input name="Decline" id="Decline" value="Decline" type="submit"> ...

Tips on updating the arrow icon after clicking on a dropdown menu

HTML: <div class="customSelectContainer"> <ul> <li class="initial">Choose</li> <li data-value="value 1">Option 1</li> <li data-value="value 2">Option 2& ...

Innovative Functions of HTML5 LocalStorage for JavaScript and TypeScript Operations

Step-by-Step Guide: Determine if your browser supports the use of localStorage Check if localStorage has any stored items Find out how much space is available in your localStorage Get the maximum storage capacity of localStorage View the amount of space ...

Activate the function only once the display has finished rendering all items from ng-repeat, not just when ng-repeat reaches its last index

Currently, I am generating a list using ng-repeat and each iteration is rendering a component tag with a unique id based on the $index value. The implementation looks like this: <div ng-if="$ctrl.myArr.length > 0" ng-repeat="obj in $ctrl.myArr"> ...

trouble seeing images with an array input and ngFor in Angular

I am encountering issues while attempting to exhibit an array of images by their source link using ngFor. It seems like there are errors hindering the functionality! Below is the image HTML code located within my card component: <div class="Session-Pa ...

Modifying the overflow behavior within a Vuetify dialog

Is there a way to have a floating action button positioned on the top right of a dialog, slightly overflowing so it's offset from the dialog itself? I'm struggling to override the 'overflow-y: hidden' property set by v-dialog. <v-dia ...

What is the method for creating a curved CSS Pseudo element background?

Currently, I have implemented a red pseudo element as part of the background for certain sections on my website. Although everything is functioning correctly, I am interested in transitioning the straight line to a curved one instead. Does anyone know ho ...

The JavaScript function is not being activated by clicking on Selenium in Chrome

Take a look at the HTML snippet below: <table class="table-main "> <thead> <tbody> <!----> <tr class="" ng-if="mapCtrl.isAdded" style=""> <td/> <td> <td> <t ...

Obtaining the dataItem of an edited cell in a Kendo grid

One issue I'm running into is retrieving the dataItem(row) when a cell in a column with a dropdown menu is updated. I've noticed that dataBind doesn't seem to be working as expected. In this project, I am utilizing Kendo Grid along with An ...

Conceal the browser scrollbars

When I have two DIVs on my webpage that are larger than a browser window, it results in a horizontal scrollbar being displayed. How can I hide this browser scrollbar for the first DIV while still showing it for the second one? For example, if I have two ...

SVGs are not resizing correctly in Internet Explorer and there is unnecessary blank space around them

Recently, I made the decision to switch to using SVG symbols for one of my projects. However, I encountered a challenge as I needed these SVGs to be responsive. My main objective was to minimize the number of HTTP requests, leading me to explore the option ...

Tips for extracting the data from a resolved promise

As a beginner in Angular, I am facing some difficulties in figuring out how to extract the value from a resolved promise. In my code, I have used $q.all([element1.$promise, e2.$promise]). This returns element1 as a JSON object. However, for element2 which ...

Refresh meta tags in a Next.js/React app

In the process of optimizing a website for SEO, I am facing the challenge of updating the meta description's content dynamically without using any third-party libraries. While I have successfully implemented the functionality, it currently requires a ...

Aligning the Navigation Bar to the Upper Right Corner

I'm attempting to rearrange my Nav Bar to be at the Top Right, with my logo on the Top Left all in one line. Unfortunately, I'm struggling to achieve this and could really use some guidance. As a newcomer to HTML and CSS, I find it challenging to ...

Transfer the choices from a dropdown list to a different JSP page

In my current JSP code, I have a select element that looks like the following: <select name="withoutAccess" size="5"> <c:foreach var="item" items="${obj.withoutAccess}"> <option>${item}</option> </c:foreach> </sel ...

The click() function in jQuery executing only once inside a "for" loop

This is an example of my HTML code: <!DOCTYPE html> <head> <title>Chemist</title> <link href="stylesheet.css" rel="stylesheet"> </head> <body> <h2 id="money"></h2> <table border="1px ...

Is the append() function malfunctioning in jQuery?

Why is it copying two lines when I only want one line to be cloned on button click? Is there a way to make sure that only a single line is copied each time the button is clicked? Here is my code: $(function() { $('.add-more-room-btn').clic ...

Footer remains fixed to the bottom of the page even when there is not enough content to

It seems like there are already many discussions on this topic, so I apologize if this is a duplicate. I searched for it but couldn't find anything similar. I am currently working on an angular application using the Ionic framework for testing purpos ...

Heroku Node Crash - ERR_INCOMPLETE_CHUNKED_ENCODING

After developing my app successfully, I encountered some errors upon deploying it to Heroku. The following issues are preventing my page from loading correctly. Can anyone provide assistance? Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING ...