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

  • Home
  • SEARCH
  • 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 4273222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:41:01+00:00 2026-05-21T07:41:01+00:00

I’m looking to write / emulate a tab strip using HTML & CSS only.

  • 0

I’m looking to write / emulate a tab strip using HTML & CSS only.

I will progressively enhance this with JavaScript and do not need any help with that.

I’ve taken ideas from this page Example 6

Here is a live example


Please feel free to be pedantic about my current HTML and CSS markup. I’m looking to write this from scratch properly using HTML5 and CSS3 standards and am hoping to avoid my usual “If it works the quality of the markup doesn’t matter. jQuery will come along and fix it for me!” attitude.


Here is my HTML currently have a markup of :

<div class="tabs">
    <section>
        <a> link 1 </a>
        <div> Content 1 </div>
    </section>
    <section>
        <a> link 2 </a>
        <div> Content 2 </div>
    </section>
</div>

Here is the (stripped) CSS :

.tabs {
    width: 100%;
}

.tabs > section > a {
    position: relative;
    display: block;
    float: left;
}

.tabs > section {
    display: inline;
}

.tabs > section:not(:target) > div {   
    position: absolute;
    padding: 20px;
    top: 50px;
    display: block;
    width: 100%;
}

There are 3 css issues that I am troubled with.

  1. The div.tabs only has floated and absolute children so does not have any “real content” and there is no border around it. How do I get it to have a proper border?
  2. the .tabs > section > div has a width of 100% but does not match the 100% width of the parent div.tabs due to the extra padding. My understanding of the box model is lacking here. How do I set it to have a width matching the div.tabs parent?
  3. How do I make the content .tabs > section > div Sit just underneath the <a> of the tab strip without setting the css top value to a finicky "43px". What’s the proper way to do generic positioning in these situations?

Disclaimer I don’t care about proper browser support. Feel free to use HTML5 / CSS3. I’ll use JavaScript to enhance the IE8 functionality properly.


If it helps this is the full CSS

.tabs {
    width: 100%;
    border: #000 solid 1px;
}

.tabs > section > a {
    position: relative;
    display: block;
    float: left;
    padding-left: 10px;
    margin-left: 5px;
    margin-right: 5px;
    padding-right: 10px;
    padding-top: 5px;
    padding-bottom: 5px;
    border: 1px solid red;
}

.tabs > section {
    display: inline;
}

.tabs > section > div {
    z-index: -2;
    background: white;
    border: 1px solid blue;
}

.tabs > section:not(:target) > div {   
    position: absolute;
    padding: 20px;
    top: 50px;
    display: block;
    width: 100%;
}
  • 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-21T07:41:01+00:00Added an answer on May 21, 2026 at 7:41 am

    I was able to get a working version of your tabs. Here is a jsFiddle version. (However, I wasn’t able to solve all your dilemmas. Read below.)

    CSS:

    .tabs {
        position: relative;
        width: 100%;
        background: #fff;
        overflow: hidden;
        padding-bottom: 100px;
        border: 1px solid #000;
        }
    
    .tabs > section > a {
        position: relative;
        display: block;
        float: left;
        border: 1px solid red;
        }
    
    .tabs > section > div {
        position: absolute;
        top: 1.5em;
        left: -50000px;
        width: 100%;
        background: #fff;
        border: 1px solid blue;
        }
    
    .tabs > section:target > div {
        left: 0;
        }
    
    .tabs > section:not(:target)#one > div {
        left: 0;
        }
    

    HTML:

    <div class="tabs">
        <section id="one">
            <a href="#one">link 1</a>
            <div> Content 1 </div>
        </section>
        <section id="two">
            <a href="#two">link 2</a>
            <div> Content 2 </div>
        </section>
    </div>
    

    Addressing the three questions:

    1. The tab div does collapse because of floating and absolutely-positioned objects. The only options I see are to set height or overflow:hidden with bottom padding.
    2. I was able to get the width set to that of div.tabs in my CSS above. That’s probably a function of position: relative.
    3. Again since all the objects are taken out of flow, I don’t see a way without JavaScript to make the section > divs aware of the anchor height.

    PS. I liked the use of :target and was able to get your content block to switch as well as have a default.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.