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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:52:58+00:00 2026-06-17T16:52:58+00:00

How would you replicate the behavior of tabs in google chrome with css? one

  • 0

How would you replicate the behavior of tabs in google chrome with css?

one problem I’m having is with the close button (x)

cursory google searches say you shouldn’t have a button inside an anchor, but if that’s the case I don’t know how to replicate the behavior.

Any ideas?

  • 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-17T16:52:58+00:00Added an answer on June 17, 2026 at 4:52 pm

    I’m going to assume that you need two separate answers to your question:

    • How do you nest the element properly?
    • How do you perform the close action?

    Let’s start with nesting the elements. I chose to make my tabs in a ul and make each tab an li within that list. The close button is an a tag that is floated to the right inside the li.

    <ul>
        <li>Tab 1 <a>x</a></li>
        <li>Tab 2 <a>x</a></li>
        <li>Tab 3 <a>x</a></li>
        <li>Tab 4 <a>x</a></li>
        <li>Tab 5 <a>x</a></li>
    </ul>
    

    (I highly recommend you give them all the appropriate classes for what you’re trying to do, but for this case, I used the minimal amount of code to keep it clean and easy to read.)

    Next up, we’ll go into performing the close action with JavaScript.

    I was able to create the following jsFiddle for you to demonstrate both of these points:

    original jsFiddle

    EDIT: revised jsFiddle

    Essentially, the code works as follows:

    $('a').click(function() {
        $(this).closest('li').animate({padding:0, margin:0, width: 0}, function () {  
            $(this).closest('li').hide();   
        });
    });
    

    When you click the a tag, which is what I’ve made the x button (similar to a chrome tab), it animates the list item (list of tabs, floated to the left) by changing the padding, margin, and width to 0.

    Technically, since I set the li to border-box for the box-sizing, I don’t have to have padding:0 in the animate function at all.

    When animation is complete, I hide the list item entirely. (I could even remove it entirely at that point if I wanted to get rid of it, but I wanted you to see what I’m doing.)

    Some additional takeaways:

    • You can have a click event on almost any item in jQuery, but certain mobile devices get finicky if they aren’t a tags.
    • You’re correct that you shouldn’t put a button inside of an anchor tag, but putting two anchor tags or a button and an anchor tag into one list item is fine.

    Everything else like setting the active tab and using a % as a max-width should be pretty obvious, but if you need more help or clarification, just let me know!

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

Sidebar

Related Questions

My question is similar to this one , but I would like to replicate
I would like to replicate the permissions from one database to another. Could that
I would like to replicate the behavior of Tuples[list, n] of Mathematica in R.
I would like to know if it would be possible to replicate the effect
Would love some opinions on this problem I'm trying to workout. I'm trying to
Is there a plugin for jQuery that would replicate the functionality exhibited on Yahoo's
So I am trying to replicate browser scroll bar behavior with div's so far
I am using Object.prototype.toString.call to identify variable types. I would expect the following behavior:
I've been wondering if it is possible to replicate the behavior of Apple's iOS5
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode

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.