Here am throwing the images from database to a div in php while, here I want to delete the image by clicking on the delete icon which has to be in the top right corner of the every image pulled from db. How could I get a delete icon in the top right corner of the images? This is how I am displaying the images in a dialog box.
<?php
$query = "SELECT * FROM files_images";
$res = mysql_query($query);
while ($row = mysql_fetch_array($res)) {
echo "<div id='popimages'>";
echo "<img title='$row[img]' id='$row[id]' style='width:100px;float:left; height:100px;margin-bottom:5px; margin-left:5px;border:2px solid #b06c1c;border-radius:10px;' src='http://localhost/PhpProject2/user_data/" . $row['filename'] . "'/>";
echo "</div>";
}
?>
You need to wrap your image with a <div>
and place your image and delete link inside that <div>
. I've created this fiddle for you, that might be what you're looking for.
If I understand correctly, try outputting something like this :
HTML
<div id='popimages'>
<div class="image">
<img class="btn-delete" onclick="alert('Do something!');" src="http://cdn1.iconfinder.com/data/icons/diagona/icon/16/101.png"/>
<img title='$row[img]' id='$row[id]' style='width:100px;float:left; height:100px;margin-bottom:5px; margin-left:5px;border:2px solid #b06c1c;border-radius:10px;' src='http://i.i.com.com/cnwk.1d/i/tim/2011/03/16/Chrome-logo-2011-03-16.jpg'/>
</div>
</div>
CSS:
.image {
width: 100px;
height: 100px;
position: relative;
}
.btn-delete {
position: absolute;
cursor: pointer;
right: 2px;
top: 2px;
/* This was edited out because it was stupid. See fernholz's answer.
left: 100%;
margin-left: -10px;
margin-top: 2px; */
}
JSFiddle: http://jsfiddle.net/TK7zB/
Drewman is technically correct, I would change .btn-delete's style to be
.btn-delete {
cursor: pointer;
position: absolute;
right: 2px;
top: 2px;
}
The top and right can be changed to whatever distance in from the corner you want the delete icon.
Adrenaxus, was pretty close, but needed a height and width on the image div and position relative, not absolute on it.
HTML:
<div class="img-pos">
<span class="close">×</span>
<img src="">
</div>
CSS:
.img-pos{
position: relative;
}
.img-pos.close {
position: absolute;
top: 2px;
right: 2px;
z-index: 100;
}