tags:

views:

51

answers:

3

I am using toggleClass and slideToggle to accomplish the following:

when the user selects a link, it will slide down the div, then it will set the link as open, displaying the appropriate background image, this is just a simple, (+) and (-) to open and close the div.

What I am having trouble with, is displaying the background-image to the right of the link, giving it about 5-10px of margin-left, to give it some spacing.

Here is a screen shot of what it is doing: Closed (displaying (+) sign): http://cl.ly/4634afa1e7aa4fe10072

Open (displaying (-) sign): http://cl.ly/8bc59ab07da46a173d62

HTML for link: <a href="#" class="our-future-intro-slide">Mapping Our Future: Strategic Plan 2010-2015</a>

CSS for when it displays the link untouched, and after it is selected:

// link is not open
.our-future-intro-slide {
    background: url('/images/uploads/images/plus_sign.png') no-repeat 120% 0%;
}

// link is open
.our-future-intro-slide-open {
    background: url('/images/uploads/images/plus-icon.png') no-repeat 120% 0%;
}

Here is the jQuery, I figure I'll throw that in, it works, just the css for making the background-image show up to the right of the text.

$(document).ready(function() {
 $('.our-future-intro-slide').click(function() {
  $(this).toggleClass("our-future-intro-slide-open");
  $(".our-future-intro").slideToggle(100);
 });
});
A: 

Try this:

.our-future-intro-slide {
    background: url('/images/uploads/images/plus_sign.png') no-repeat top right;
    padding-right: 30px; /* or whatever the width of the background image is */
}

And, of course, the same modifications for the other rule.

Ryan Kinal
Looks better, but still off. normal state: http://cl.ly/1c32343005e752c16706, hovered state: http://cl.ly/2db77f5d9941c5d39146clicked and not hovering over it: http://cl.ly/ba3a7ce568000881d509clicked hover state: http://cl.ly/5e216694af83db326844
Brad
Did you add the padding to the hover states? You may need to adjust the padding, or perhaps use "center right" instead of "top right", depending on how you want it to look.
Ryan Kinal
`background: url('/images/uploads/images/plus_sign.png') no-repeat right top;` (example - http://www.w3schools.com/css/tryit.asp?filename=trycss_background_shorthand)
bancer
I added it to both a:link and a:hover for both classes
Brad
'right' should be in front of 'top'
bancer
oops, I just set the hovers to display:none; hopefully this works in IE
Brad
Screws it up in IE, I love IE
Brad
A: 

I think you will be interested in this post - Pure CSS "Popups".

UPDATE: that's another way to align images on links hover.

bancer
Why -1? Explain, please.
bancer
A: 

idk if I understand totally but have you tried using an " :after " ??? like .link:after{ background: #FFF; } or whatever...

Luke3butler
I am trying to align the image to the right of the text, I am successful in displaying the appropriate images based on the state of the link, but just need to align them just right.
Brad
yes... thats what I thought... and :after doesnt work?.. after is "right"... every code turns out different of course.. and idk if IE ruins it all or whatever..
Luke3butler