On hover I want a link apear at the top-right of the image. Just like on your profile picture on Facebook, where it says \"Change Picture\".
I have tried to to get it wo
This is the way I done it: CSS:
.imgHover {
display: inline;
position: relative;
}
.imgHover .hover {
display: none;
position: absolute;
right:0;
z-index: 2;
}
HTML:
<div class="imgHover">
<div class="hover"><a href="htpp://google.com">Edit</a></div>
<img src="http://img14.imageshack.us/img14/9698/29588166.jpg" alt="">
</div>
JQuery:
$(function() {
$(".imgHover").hover(
function() {
$(this).children("img").fadeTo(200, 0.85).end().children(".hover").show();
},
function() {
$(this).children("img").fadeTo(200, 1).end().children(".hover").hide();
});
});
Test this on jsfiddle.
If the imgHover is made to match its contents, then it should just have position:relative
and the hover class have position:absolute
and top:0;right:0
Example at http://www.jsfiddle.net/FvBqA/
Try
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<style>
.imgHover {
display: inline;
position: relative;
}
.imgHover .hover {
display: none;
position: absolute;
right: 5px;
top: 5px;
z-index: 2;
}
</style>
</head>
<body>
<script>
$(function() {
$(".imgHover").hover(
function() {
$(this).children("img").fadeTo(200, 0.25).end().children(".hover").show();
},
function() {
$(this).children("img").fadeTo(200, 1).end().children(".hover").hide();
});
});
</script>
<div class="imgHover"><div class="hover"><a href="htpp://google.com">Edit</a></div><img src="http://img14.imageshack.us/img14/9698/29588166.jpg" alt=""></div>
</body>
</html>
make your image a background for div with relative positioning and add inner div to it with the overlay content style it with display:none
then imgdiv:hover innerdiv{display:block} will do the trick
You need to absolute position the link in a container that has position different than the normal flow. In this example I use relative for that on the container. Try this:
HTML
<div class="imgHover">
<div class="imgContainer">
<a href="http://google.com">Edit</a>
<img src="http://img14.imageshack.us/img14/9698/29588166.jpg" alt="" />
</div>
</div>
CSS
.imgHover { float: left; }
.imgContainer { position: relative; }
.imgContainer a { display: block; position: absolute; top: 0; right: 0; background: Green;}