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 6803419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:20:31+00:00 2026-05-26T19:20:31+00:00

So I want to create a tab system using only CSS. what I have

  • 0

So I want to create a tab system using only CSS.

what I have so far works, but I don’t know how to make one tab visible by default.

The tabs:

<section class="tabs">

  <ul>
   <li><a href="#tab1">1</a></li>
   <li><a href="#tab2">2</a></li>
   <li><a href="#tab3">3</a></li>
  </ul>

  <section id="tab1"> content for 1... </section>
  <section id="tab2"> content for 2... </section>
  <section id="tab3"> content for 3... </section>

</section>

and the css (the most important part):

.tabs section{
 display: none;
}

.tabs section:target{
 display: block;
}

So I if I set the section:first-child to block (first tab should be visible by default), then I get two visible sections if there’s a anchor in the URL: the first tab, and the target tab…

How can I overcome this problem?

  • 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-05-26T19:20:32+00:00Added an answer on May 26, 2026 at 7:20 pm

    Well, if you make your default your last tab (section:last-child), then I think this could work:

    .tabs section,
    .tabs section:target ~ section {
       display: none;
    }
    

    Using the general sibling selector ~ requires that the element precede the siblings it targets, so hence the reason for the last-child rather than first-child requirement.

    EDIT: 11-12-2011, I did find a way for you to highlight your a tags as active! Assuming it meets your particular application. Here is some simple modified code for proof of concept (only tested in FF):

    HTML

    <section class="tabs">
      <ul class="nav">
       <li><a href="#tab1">1</a></li>
       <li><a href="#tab2">2</a></li>
       <li><a href="#tab3">3</a></li>
      </ul>
    
    
      <section id="tab2"><div class="tabActive"></div> content for 2... </section>
      <section id="tab3"><div class="tabActive"></div> content for 3... </section>
      <section id="tab1"><div class="tabActive"></div> content for 1... </section>
    
    </section>
    

    CSS

    .nav {
        position: relative;
        z-index: 2;
        margin: 10px .5em 0;
    }
    .nav li {
        padding: .5em;
        width: 2em;
        text-align: center;
        float: left;
    }
    
    .tabs section,
    .tabs section:target ~ section {
       display: none;
    }
    
    .tabs section:target,
    .tabs section:last-child {
        display: block;
        clear: left;
        margin: 0 .5em;
        min-width: 300px;  /* for show only */
        min-height: 200px; /* for show only */
        border: 1px solid black;   
        position: relative;
        z-index: 1;
        padding: 10px;
    }
    
    .tabActive { /* set for tab 1 */
        width: 2em;
        height: 2em;
        position: absolute;
        top: -2em;
        left: .5em;
        border: 1px solid black;
        border-bottom: transparent;
        background-color: inherit;
        margin-top: -1px; /* top border height */
        margin-left: -1px; /* left border width */
    }
    
    #tab1 {background-color: cyan;}
    #tab2 {background-color: yellow;}
    #tab3 {background-color: pink;}
    
    #tab2 .tabActive {left: 3.5em;}
    #tab3 .tabActive {left: 6.5em;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a tab UI, but I don't want to put
I want to create a tab using child tab having intents, so that when
I want to create a Tableview in a Tab bar application. Because I'm using
I want to create a Tab Control that only opens content once. Each item
I have application in which i have create tab-bar dynamically. Now i want to
I want to create a tab/widget/thingymajiggy like the feedback-thing in this picture: That behaves
i want create image animation , i have 50 images with png format now
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the
Say that I have a system service, and I want to offer a low-level

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.