I’m stumped trying to figure out a way to have a different background on my <li> elements when an <a> inside of them is selected.
I’m also using a Jquery tabbing feature called idTabs to navigate to various anchors when clicked to give the appearance of tabs. It’s really all a one page website.
The difficulty is in trying to get a different “selected” sort of background on the tab link <li> that has just been clicked.
So the tabBacker CSS has a colored background and I’d like that to switch to an image when that link is selected. But the anchor link is inside the <li> that needs the switched background. It like to call an image called button-backer_on.gif as a background when selected.
Here’s current CSS:
.idTabs li { float:left; width:234px; height:94px; background-color:#2f2f2f; font-size:18px; text-align:center; } .idTabs li a { color:#ffffff; } .tabBorder { border-right:1px solid #3c3c3c; } .tabBackers { background-color:#353535; } .tabBackers a.selected { background:#0082c8 url(../img/button-backer_on.gif) top left no-repeat; }
And the dev link:
I also got to figure out to center that button text Vertically in the <li> … weird problem …
You could set the UL to display: table and the LIs to display: table-cell (remove the float) and vertical-align: middle and set the width and height on the LIs that was on the As. Then you’d have to remove display: block from the As and put the blue background on the LIs on hover and when selected.
I am slowly getting the picture. What I was missing in the past post was the vertical align middle part. That snapped everything horizontal nicely.
My last issue is, I still don’t see how to do a .selected on an <li>. I tried to display the <li> as an anchor or something, but it didn’t work. I can’t do this on a hover because it’s just required for the “pages” that are deemed in the “on” state.
So, that will make the menu item blue when you hover over it, and it will also be blue if you add a class of “selected” to the LI, which you would do when that menu link’s content is visible. At the moment, the “selected” class is being placed on the <a> … which is probably better, but using display: table and vertical-align center makes it hard (if not impossible) to get the <a> to fill the menu item space.
So I’d look at editing the JS so the .selected class is placed on the LI instead.
Edit:
Personally, I use this script for tabs, which happens to add the “selected” class to the LI, so that may be an easier route to follow.
I’m starting to think this aint possible. Nothing will switch the damn class of another element. It always thinks I want to deal with an anchor.
Haven’t I seen this butt simple move done a million times all over the damn internet? Shouldn’t be this hard. They never even mentioned having the hover effect, but now that you do … yeah let’s do that too. That link you pasted in is cool. Not really a plugin though is it? More like a guy just trying to tell you how to do this from scratch which I don’t have the time for right now unfortunately. Do i need to stat over? What gives?
Even if i learn his way, it’s not gonna switch the class of a different element.
I think for my purposes today with limited time and all I’m just gonna go down and dirty