Reputation: 9552
My background image having width:118px
,On clicking on background image i want to perform some jquery, i cant use <a>
tag.How to make cursor:pointer
only on background
and how to give a class name only for the background? Is it possible? how?
<div id="post1_img"></div>
#post1_img
{
width:280px;
height:33px;
background:url(../images/assets/pullTab-readMore-off-.png) no-repeat top center;
clear:both;
}
EDIT
clicking on read more i want to perform some action,Is it possible to do without creating any extra div
width of div:280px;
width of image:118px;
http://jsfiddle.net/prash/A8FWa/
Upvotes: 1
Views: 978
Reputation: 32192
Hey now used to after
properties in your css
<div id="post1_img"></div>
Css
#post1_img
{
width:280px;
height:33px;
background:url(http://www.gravatar.com/avatar/9932debdde3decc7726b508f43d57438?s=32&d=identicon&r=PG) no-repeat top center;
clear:both;
border:1px solid black;
position:relative;
}
#post1_img:after{
content:'';
position:absolute;
top:0;
left:50%;
margin-left:-16px;
width:32px;
height:33px;
cursor:pointer;
}
Upvotes: 2
Reputation: 1143
You cannot put a class name to a background image only html elements, but there are some work arounds. I would suggest you put the image in a div and use cursor:pointer; and position: absolute; and set the z-index: -1; and layer another div over it.
Now that I see your update and screen shot, all you have to do is float an absolute div over the section of the page with something like:
#bgmask{
width:70px;
height:70px;
position: absolute;
right:10%;
top: 0;
z-index:999;
cursor:pointer;
}
HERE IS A JSFIDDLE: http://jsfiddle.net/collabcoders/xLx68/1/
Upvotes: 1
Reputation: 23300
You put cursor: pointer
in your CSS class post1_img
and then you put cursor: <something else>
in the style/CSS of everything that's inside it.
Example, if your DIV contains just a form (so everything is an input
element of different type
):
#post1_img {
cursor:pointer;
width:280px;
height:33px;
background:url(../images/assets/pullTab-readMore-off-.png) no-repeat top center;
clear:both;
}
#post1_img input {
cursor: auto; /*just an example*/
}
As for giving a class name for the background, it's not possible because the background is not an HTML element per-se.
EDIT: Fixed the cursor
in the second css block
Upvotes: 1
Reputation: 7773
you can put the background image as an background of a div which has the same dimension with the image. then place this div centered inside another div.
<div id="outer">
<div id="post1_img">
</div>
</div>
//css
#post1_img{
width:70px;
cursor:pointer;
background:url(pullTab-readMore-off-.png) no-repeat top center;
/*you need more css here to adjust this div to be center of the outer div*/
}
#outer{
width:280px;
}
//jquery
$('#post1_img').click(function(){
//do something
});
Upvotes: 1