/    Sign up×
Community /Pin to ProfileBookmark

Using CSS for Tabbed Browsing

Hi everyone,

I have been trying to implement some css tabbed navigation and can’t quite get it working. What I want is content that is displayed based on which tab I click (I guess that’s what tabbed browsing is right ? ) and I don’t want to have to load a new page. Can this be done with css?

So far, this is my mark up. As you can see I’m trying to apply the style in the #ubuntuMenu li a:focus+ul section to the currently selected content. I’ve tried a few other pseudo classes with and without the sibling “+”. Still no luck.

Any ideas on how I could work this one?

Thanks

CSS

[code]
#ubuntuMenu li
{
float: right;
display: block;
margin-left: 1em;
}

#ubuntuMenu ul
{
display: none;
}

#ubuntuMenu li a:focus+ul
{
display: block;
position: absolute;
left: 0px;
margin-right: 10px;
}
[/code]

HTML

[code]
<ul id=”ubuntuMenu”>
<li>
<a title=”View the top 5 videos” href=”#ubuntuTop5″>top 5</a>
<ul id=”ubuntuTop5″>
<li>
<h3>Clean Install of Hardy Heron</h3>
<p>This is a snippet of text on this topic</p>
</li>
</ul>
</li>
<li>latest</li>
<li>versions</li>
</ul>
[/code]

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@jmccreaApr 18.2008 — From what I can tell it's not possible using pure css. However using JavaScript it is possible. Check this site out: http://docs.jquery.com/UI/Tabs
Copy linkTweet thisAlerts:
@DJRobThaManauthorApr 18.2008 — arrgghhh... I was hoping you wouldn't say that.

But thanks for the help.
Copy linkTweet thisAlerts:
@CentauriApr 19.2008 — It would have to be [CODE][COLOR="Red"]#ubuntuMenu li:focus ul[/COLOR] {
display: block;
position: absolute;
left: 0px;
margin-right: 10px;
}[/CODE]
as the second level <ul> is within the <li> and not the <a>. Note that a suckerfish type javascript will be required to get this to work in IE6 - modern browsers are fine.
Copy linkTweet thisAlerts:
@DJRobThaManauthorApr 21.2008 — Tried that one already centauri and it didn't work. But now that I think about it, as much as I dislike javascript and didn't really want to incorporate it, that has to be the way to go. Using the :focus pseudoclass will not allow the most recently selected tab to remain active when another part of the page is clicked. I've already impemented it and it's only about 4 lines of javascript. I think I can live with that.

?
×

Success!

Help @DJRobThaMan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...