What is the best way to position a floating image at the top right corner of a div?

When I dynamically generate a bunch of divs with long text that wraps, the floating delete icon ends up at the bottom. Although it's acceptable, I prefer not to use absolute positioning and would like to adjust the width based on the container.

Take note that the width is static in this example, but it varies based on the container in my actual usage. As a last resort, I may resort to using absolute positioning if necessary.

Check out the issue I'm facing in this example.

<div class="deletableGroup">Marketing Department
    <img title="delete" src="http://icons.iconarchive.com/icons/dryicons/simplistica/16/delete-icon.png"/>
</div>
<div class="deletableGroup">Sales
    <img title="delete" src="http://icons.iconarchive.com/icons/dryicons/simplistica/16/delete-icon.png"/>
</div>

CSS:

.deletableGroup img {
    padding-left: 5px;
    padding-top: 2px;
    cursor: pointer;
    float: right;
}
.deletableGroup {
    width: 125px;
    padding: 2px;
    border: solid 2px lightskyblue;
    background-color: #F5F5F5;
    border-radius: 5px;
    margin: 3px;
    display: inline-block;
}

Answer №1

To efficiently address this issue, it would be best to reposition the <img> element above the text...

<div class="removableSection">
    <img title="remove" src="http://icons.iconarchive.com/icons/dryicons/simplistica/16/delete-icon.png" />
Sales Department
</div>

Check out an updated demonstration here

Answer №2

Include the following code snippet:

HTML :

<div class="removableSection">
    <img title="remove" src="http://icons.iconarchive.com/icons/dryicons/simplistica/16/remove-icon.png"/>
    Sales Department    
</div>

CSS :

.removableSection img{
    float:right;    
}

Fiddle : http://jsfiddle.net/abc123/5/

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

iOS 14.7.1 causing issues with CSS aspect ratio feature

I created an application that utilizes the aspect ratio CSS property to manage the width of an element by only specifying its height. Unfortunately, when testing it on my Iphone 11 running iOS 14.7.1, the aspect ratio doesn't seem to function properly ...

How to implement a modal popup in Vue.js using an anchor tag

As a newcomer to Vue.js, I'm facing an issue with creating a link in my navbar component that, when clicked, displays a modal component. I've noticed that the solutions I found are for buttons which use the data target attribute, but this isn&apo ...

Form submission not being recognized by Ajax's .done() function

I'm trying to include a form from another file using ajax. It's a simple form that is activated by an onclick event defined as follows: <a href="javascript:void(0);" class="remitir" title="Reemitir Solicitud" data-id="'.$value['idso ...

Center aligning two images within a bootstrap column

I have a webpage template in HTML and I'm looking to incorporate Bootstrap into it. Currently, I have two images within a Bootstrap column. I want to ensure that both images remain aligned and adjacent to each other, while also being centered in the m ...

Creating precise squares in JavaScript and animating their movement at designated intervals

My goal for the Final Project is to create a JavaScript-based game similar to Guitar Hero, but with squares instead of circles representing the notes. In Guitar Hero, players have to hit the notes at specific times. I am facing a challenge in my code wher ...

Retrieve variables from an external JavaScript file

I need to fetch the currentID variable from renderermain.js and utilize it in renderermem.js. However, I am looking for a way to achieve this without modifying mem.html: <script src="renderermain.js"></script> <script src="renderermem.js"& ...

What sets bootstrap.css apart from bootstrap-responsive.css?

Can you explain the difference between bootstrap.css and bootstrap-responsive.css? I'm unsure which one is best for creating responsive websites. ...

Fade or animate the opacity in jQuery to change the display type to something other than block

I am currently using display: table and display: table-cell to vertically align multiple divs. However, I have encountered an issue when animating the opacity with jQuery using either fadeTo() or fadeIn. The problem is that it always adds inline style di ...

Breaking HTML attribute values into separate lines will make the code more organized and easier

Is it possible to format HTML attribute values so they can span across multiple lines? Essentially, I'm wondering if there is a way to include line breaks within a regular typed HTML attribute value. For instance, in the functional code snippet below ...

Position <UL> at the center of <DIV>

I've attempted several solutions found on Stack Overflow to center my <UL> element, but nothing seems to work. Can someone please take a look at it? I am looking to center the text "Shop 943 01 ... not available". Thank you in advance. ...

Menu that adjusts to fit your browsing needs

Struggling to implement a fixed bottom menu on my page. Can anyone help with making it responsive? I've attempted to create the menu, but I'm having trouble linking the logo and menu items together. HTML <header class="header"> ...

What is the best way to implement a "number of users currently online" feature in a Meteor application?

Currently, I am developing a Meteor application and I am interested in implementing a feature that displays the number of users currently visiting the website, much like omegle.com which shows "38,000+ online now" or a similar message. I'm unsure if t ...

What are the basics of floating elements and how can it be effectively utilized in CSS3?

I can't wrap my head around this property. First, let me share what I know about it. I'm focusing on the <p> element with id="amazing" for this discussion. Let's set a width for it #amazing{ width: 200px } The outcome is: Since ...

The value of the parameter '<' has been converted to '<'

I am currently utilizing ExpressJS in conjunction with the body-parser library. Upon passing a parameter value of 2<5, it is observed to be altered and converted to 2&lt;5 read: async (req, res, next) => { try { let condition= req.q ...

Increment and decrement the like count on fa-heart multiple times

Is there a way to increment the count of a fa-heart value on click and decrement it on the second click? The issue I'm facing is that I have multiple fa-heart elements on the same page, making it challenging to increment or decrement the clicked fa-h ...

JavaScript scrollable selection menu with a favorite option button

I am looking to enhance a standard select element by adding a favorite button that can be toggled on and off for each option. Utilizing Bootstrap for styling, I want to create a user interface element that allows for smooth scrolling through the options an ...

Placing content in bottom and moving towards the left side

On my webpage, I have a div that I would like to fill with content similar to the image. How can I achieve this without resizing the div and instead populate it from bottom to top? ...

Capturing HTML elements based on their class names using regular expressions

In my Python script, I am attempting to extract both the element and class names for all elements within an HTML file. So far, I have successfully retrieved all class names using the code snippet below. This method is crucial as I will be processing numero ...

Concealing the pagination buttons for next and previous in Material-UI TablePagination

Is there a way to remove the next and prev buttons in the TablePagination component without affecting the position of the "Showing ..." text? Should I handle this through CSS styling or by configuring the component settings? https://i.sstatic.net/7EkKd.pn ...

The background image constantly shifts while scrolling on a mobile device

Just sharing my first post here. There's been something bothering me on my personal website for quite some time. Whenever I visit the site on my Android phone and start scrolling through the page, the background image seems to 'adjust' itse ...