How can I make the floating image float to the top right of the div?


Smeggs

I have a bunch of dynamically generated divs. When the text is longer, it will automatically wrap. That's fine, but the floating delete icon floats to the bottom.

A few things to note before looking at the code. The width in the example is static, but in my usage the width is defined by the container. I'd rather not use absolute positioning and keep it as a last resort.

Here's an example of what I'm talking about ( http://jsfiddle.net/3FYv8/1/ )

<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;
}
Muse Fan

The quickest way to fix this is to move <img>in front of the text ...

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

Here is an updated example

Related


How can I make the div go to the right?

User 12655615 I have an image in a div and I want it to go to the right. Right now it just keeps sticking to the left, overlapping another image in the div. Any idea how to do this? Himanshu Singh You can use text-align: rightalign the image to the right. .myD

Can't make image float to the right of UL

Sonnyoz I'm trying to make the image float to the right of the p and ul tags... but the individual list items are always out of focus and appear after the bottom of the image. I've tried many different approaches (after reading other people's understanding of

How can I make the parent height of the floating div be 100%?

Nathan Osman Here is the HTML: <div id="outer"> <div id="inner"></div> Test </div> Here is the CSS: #inner { float: left; height: 100%; } After checking with Chrome developer tools, the height of the inner div is 0px. How can I force it to be 100

How can I make the parent height of the floating div be 100%?

Nathan Osman Here is the HTML: <div id="outer"> <div id="inner"></div> Test </div> Here is the CSS: #inner { float: left; height: 100%; } After checking with Chrome developer tools, the height of the inner div is 0px. How can I force it to be 100

How can I make the parent height of the floating div be 100%?

Nathan Osman Here is the HTML: <div id="outer"> <div id="inner"></div> Test </div> Here is the CSS: #inner { float: left; height: 100%; } After checking with Chrome developer tools, the height of the inner div is 0px. How can I force it to be 100

How can I move that button to the top right of the div?

Christopher Altamirano I'm trying to put a button in the top right corner, I'm making a static youtube page for practice. I don't want to give it some padding directly in the corners. .anotherDescription { background-color: white; width: 800px; height: 1

How can I move that button to the top right of the div?

Christopher Altamirano I'm trying to put a button in the top right corner, I'm making a static youtube page for practice. I don't want to give it some padding directly in the corners. .anotherDescription { background-color: white; width: 800px; height: 1

How can I move that button to the top right of the div?

Christopher Altamirano I'm trying to put a button in the top right corner, I'm making a static youtube page for practice. I don't want to give it some padding directly in the corners. .anotherDescription { background-color: white; width: 800px; height: 1

Firefox floating bug? How can I get float:right on the same line?

Scotty: I have the following fiddle: http://jsfiddle.net/q05n5v4c/2/ In Chrome it renders fine. The chevrons are on the right. However, in Firefox it drops the Chevron by 1 line. I searched google and found several articles about this bug, but none of these su

Firefox floating bug? How can I get float:right on the same line?

Scotty I have the following fiddle: http://jsfiddle.net/q05n5v4c/2/ In Chrome it renders fine. The chevrons are on the right. However, in Firefox it drops the Chevron by 1 line. I searched google and found several articles about this bug, but none of these sug

Firefox floating bug? How can I get float:right on the same line?

Scotty: I have the following fiddle: http://jsfiddle.net/q05n5v4c/2/ In Chrome it renders fine. The chevrons are on the right. However, in Firefox it drops the Chevron by 1 line. I searched google and found several articles about this bug, but none of these su

Firefox floating bug? How can I get float:right on the same line?

Scotty: I have the following fiddle: http://jsfiddle.net/q05n5v4c/2/ In Chrome it renders fine. The chevrons are on the right. However, in Firefox it drops the Chevron by 1 line. I searched google and found several articles about this bug, but none of these su