0

I'm planning on making a tabbed navigation on the site i'm designing. Initially, you could create it in javascript. But if someone browses the web w/ Javascript turned off. Then they won't see the links pointed to by other tabs.

Hope you could give me tips on this one. ON this site(stackoverflow). I've tried the tabbed navigation here with JS disabled and yet the tabbed navigation works. Any tips on how can i achieve that.

<ul class="tabbed-nav">
    <li><a href="#section1">Tab 1</a></li>
</ul>
<div class="tabbed-content">
    <div id="section1">I'm tab1</div>
</div>
chanHXC
  • 611
  • 1
  • 7
  • 17

2 Answers2

3

I did something similar a few months back...

http://lloydsbankinggroupapprentices.com/

Take a look at the "Brands" section on the homepage.

With JS turned off, the href on the anchors essentially pull the content into view. Nice little trick I saw on csstricks some time ago. Can't find the page now though..?

The CSS is quite simple:

.tabbed-nav li a{
display: block;
padding: 3px 10px;
margin-right: 1px;
background: #666;
color: #fff;

}

.tabbed-content{
position: absolute;
top: 35px;
height: 100px;
overflow: hidden;
width: 100%;

}

.tabbed-content div{
position: relative;
height: 100px;
width: 300px;

}

And here's a JS fiddle showing purely css tabbed content.

http://jsfiddle.net/danvoyce/DUL6N/

Give us a shout if you have any queries!

DanV
  • 3,193
  • 4
  • 29
  • 43
  • 1
    Try to post some actual working code. This link could change in future and would become useless answer for anyone else. – Michael Giovanni Pumo Feb 19 '13 at 10:39
  • My bad. Still a noob to this place! I've updated with a css snippet and a fully working fiddle. – DanV Feb 21 '13 at 09:04
  • @DanV Yeah that's nice trick of specifying a fixed height to the tabbed-contents and using overflow:hidden on it's container. But this seems impractical since you won't know the height of an element beforehand. – chanHXC Feb 26 '13 at 04:35
1

With a tool like jQuery, achieving this is the simplest of tasks.

Check this JS fiddle: http://jsfiddle.net/sqfSA/

Also, see this page for Tabs UI feature: http://jqueryui.com/tabs/

Straight HTML is used with CSS as normal, and then JS is used to hide / show tabs. This results in visible data if JS is disabled.

Hope that helps.

Full code because Stack Overflow requires it (you can copy and paste this to your own app, to see it working):

<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Tabs - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/tabs/resources/demos/style.css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>
</body>
</html>
Michael Giovanni Pumo
  • 14,338
  • 18
  • 91
  • 140
  • since the tab's interface depends on jQuery UI, i think the design would break. – chanHXC Feb 19 '13 at 03:38
  • @chanHXC How would it 'break'? Sorry, I'm not understanding your comment. My solution made use of jQuery, which in turn, requires jQuery UI for interface elements like tabs. It works perfectly the way the original poster described it should. – Michael Giovanni Pumo Feb 19 '13 at 10:41
  • What i mean is if Javascript is disabled the design would probably break since it relies on jQuery and jQueryUI. Though i haven't tried jQueryUI. – chanHXC Feb 19 '13 at 14:49
  • 1
    @chanHXC That's not strictly true. For example, you can style classes on the HTML with CSS before even calling the tabs function. Then, you only have to use the active class (generated by JavaScript) to show / hide as needed. No CSS would have to rely on class names generated by the JavaScript. – Michael Giovanni Pumo Feb 19 '13 at 14:54
  • yeah i'm wrong. Sorry. i think my approach on this one would be. Don't initially hide the tab-contents on CSS, let JS/jQuery handle that functionality $(".tab-contents:not(:first-child)").hide(); btw, thank you very much. – chanHXC Feb 20 '13 at 11:03
  • 1
    @chanHXC Yep, you got it! If this answered your question, please consider marking it as correct so the whole community can benefit in future. Happy coding! – Michael Giovanni Pumo Feb 20 '13 at 15:13