Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8479529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:03:08+00:00 2026-06-10T19:03:08+00:00

I am trying to make my css tabs compatible for mobile devices, especially for

  • 0

I am trying to make my css tabs compatible for mobile devices, especially for IOS. Also I want to use 3 different tabs on my page. I have no jquery knowledge, so I tried to find an example. The best example I found was using this structure;

<ul id="tabs">
<li><a href="#" name="tab1">One</a></li>
<li><a href="#" name="tab2">Two</a></li>
<li><a href="#" name="tab3">Three</a></li>
<li><a href="#" name="tab4">Four</a></li>    
</ul>

<div id="content"> 
<div id="tab1">...</div>
<div id="tab2">...</div>
<div id="tab3">...</div>
<div id="tab4">...</div>
</div>

and its jQuery is;

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
    $("#content div").hide(); // Initially hide all content
    $("#tabs li:first").attr("id","current"); // Activate first tab
    $("#content div:first").fadeIn(); // Show first tab content

    $('#tabs a').click(function(e) {
        e.preventDefault();
        if ($(this).closest("li").attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        $("#content div").hide(); //Hide all content
        $("#tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $('#' + $(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });
});
</script>

There is a small problem. I do not want to use id for tabs. I changed id with classes then modified the CSS. I tried to modify the script but it wont work:(
There are three different tab groups on my page, that’s why I am changing it to classes.
My new tabs are;

<ul class="tabs">
<li><a href="#" name="tab1">One</a></li>
<li><a href="#" name="tab2">Two</a></li>
<li><a href="#" name="tab3">Three</a></li>
<li><a href="#" name="tab4">Four</a></li>    
</ul>

<div class="tabs_content"> 
<div id="tab1">...</div>
<div id="tab2">...</div>
<div id="tab3">...</div>
<div id="tab4">...</div>
</div>

And tried to change jQuery as;

<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
    $(".tabs_content div").hide(); // Initially hide all content
    $(".tabs li:first").attr("id","current"); // Activate first tab
    $(".tabs_content div:first").fadeIn(); // Show first tab content

    $('.tabs a').click(function(e) {
        e.preventDefault();
        if ($(this).closest("li").attr("id") == "current"){ //detection for current tab
         return       
        }
        else{             
        $(".tabs_content div").hide(); //Hide all content
        $(".tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $('#' + $(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });
});
</script>

Can you please help me with the jQuery? Or show me a better example for multiple tab tables within the same page?
Thanx in advance

edit: With the change now when I use one tab group other tab groups’ contents are hidden 🙂

And this is the CSS file;

    .tabs{
      overflow: hidden;
      width: 100%;
      margin: 0;
      padding: 0;
      list-style: none;
    }

    .tabs li{
      float: left;
      margin: 0 .5em 0 0;
    }

    .tabs a{
      position: relative;
      background: #ddd;
      background-image: linear-gradient(to bottom, #fff, #ddd);  
      padding: .7em 3.5em;
      float: left;
      text-decoration: none;
      color: #444;
      text-shadow: 0 1px 0 rgba(255,255,255,.8);
      border-radius: 5px 0 0 0;
      box-shadow: 0 2px 2px rgba(0,0,0,.4);
    }

    .tabs a:hover,
    .tabs a:hover::after,
    .tabs a:focus,
    .tabs a:focus::after{
      background: #fff;
    }

    .tabs a:focus{
      outline: 0;
    }

    .tabs a::after{
      content:'';
      position:absolute;
      z-index: 1;
      top: 0;
      right: -.5em;  
      bottom: 0;
      width: 1em;
      background: #ddd;
      background-image: linear-gradient(to bottom, #fff, #ddd);  
      box-shadow: 2px 2px 2px rgba(0,0,0,.4);
      transform: skew(10deg);
      border-radius: 0 5px 0 0;  
    }

    .tabs #current a,
    .tabs #current a::after{
      background: #fff;
      z-index: 3;
    }

    .tabs_content
    {
        background: #fff;
        padding: 2em;
        height: 220px;
        position: relative;
        z-index: 2; 
        border-radius: 0 5px 5px 5px;
        box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, .5);
    }

My new settings are;

Script is;

    <script type="text/javascript" src="jquery-1.8.1.js"></script>

    <script>
    $(function(){
        //INIT IS NOT NECESSARY IF YOU FOLLOW MY CODE

    $("#tabs a").click(function(){
        //ADD ACTIVE CLASS
        $(this).parent().siblings().removeClass("current");
        $(this).parent().addClass("current");
        //SHOW CONTENT
        $(".content-holder").removeClass("current");
        var myIndex = $(this).parent().index(); // gets the index of the LI clicked
        $(".content-holder").eq(myIndex).fadeIn();
    });
    });
    </script>
HTML is;

        <ul class="tabs">
        <li class="tab current"><a href="#" name="tab1">One</a></li>
        <li class="tab"><a href="#" name="tab2">Two</a></li>
        <li class="tab"><a href="#" name="tab3">Three</a></li>
        <li class="tab"><a href="#" name="tab4">Four</a></li>    
        </ul>

        <div class="content"> 
        <div class="content-holder current" id="tab1">content1</div>
        <div class="content-holder" id="tab2">content2</div>
        <div class="content-holder" id="tab3">content3</div>
        <div class="content-holder" id="tab4">content4</div>
        </div>


and my css is;
.tabs{
  overflow: hidden;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tabs li{
  float: left;
  margin: 0 .5em 0 0;
}

.tabs a{
  position: relative;
  background: #ddd;
  background-image: linear-gradient(to bottom, #fff, #ddd);  
  padding: .7em 3.5em;
  float: left;
  text-decoration: none;
  color: #444;
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
  border-radius: 5px 0 0 0;
  box-shadow: 0 2px 2px rgba(0,0,0,.4);
}

.tabs a:hover,
.tabs a:hover::after,
.tabs a:focus,
.tabs a:focus::after{
  background: #fff;
}

.tabs a:focus{
  outline: 0;
}

.tabs a::after{
  content:'';
  position:absolute;
  z-index: 1;
  top: 0;
  right: -.5em;  
  bottom: 0;
  width: 1em;
  background: #ddd;
  background-image: linear-gradient(to bottom, #fff, #ddd);  
  box-shadow: 2px 2px 2px rgba(0,0,0,.4);
  transform: skew(10deg);
  border-radius: 0 5px 0 0;  
}

.tabs #current a,
.tabs #current a::after{
  background: #fff;
  z-index: 3;
}

.content
{
    background: #fff;
    padding: 2em;
    height: 220px;
    position: relative;
    z-index: 2; 
    border-radius: 0 5px 5px 5px;
    box-shadow: 0 -2px 3px -2px rgba(0, 0, 0, .5);
}

.content-holder {
    display:none;
}
.content-holder.current {
    display:block;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:03:10+00:00Added an answer on June 10, 2026 at 7:03 pm

    I setup a plugin that can handle multiple tab sets.

    (function ($) {
        $.fn.tabset = function () {
            var $tabsets = $(this);
            $tabsets.each(function (i) {
                var $tabs = $('li.tab a', this);
                $tabs.click(function (e) {
                    var $this = $(this);
                        panels = $.map($tabs, function (val, i) {
                            return $(val).attr('href');
                        });
                    $(panels.join(',')).hide();
                    $tabs.removeClass('selected');
                    $this.addClass('selected').blur();
                    $($this.attr('href')).show();
                    e.preventDefault();
                    return false;
                }).first().triggerHandler('click');
            });
          };
    })(jQuery);
    

    You’ll have to wrap your html in a div containing both the tabs and the content. Also you need to update your anchors to use a standard hash tag, see below:

    <div class="tabset">
        <ul class="tabs">
            <li class="tab"><a href="#tab1">One</a></li>
            <li class="tab"><a href="#tab2">Two</a></li>
            <li class="tab"><a href="#tab3">Three</a></li>
            <li class="tab"><a href="#tab4">Four</a></li>    
        </ul>
    
        <div class="panel" id="tab1">...</div>
        <div class="panel" id="tab2">...</div>
        <div class="panel" id="tab3">...</div>
        <div class="panel" id="tab4">...</div>
    </div>
    

    You can call it like so:

    $('div.tabset').tabset();
    

    You can see a working example including three tab sets at: http://jsfiddle.net/rustyjeans/XVp5X/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to make custom radio buttons using HTML, CSS, and JavaScript.
I have been trying to get yui-css grid system to make a three column
I have am trying to modify the following example and make vertical tabs I
I'm trying to make a CSS only zebra table which is compatible with IE
I'm trying to make an iOS-style toggle switch in HTML/CSS/JavaScript. It's at the point
I'm trying to make a live, in-page css editor with a preview function that
I'm trying to make a cross browser CSS nav-bar for mobile and desktop using
I am trying to make a menu in javascript/JQuery (css is also an option)
I'm trying to make a css background flash between two colours. The best solution
I am trying to make the css curve box with gradient and shadow as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.