Conceal the lower border of a targeted Tab using HTML

I'm working on a horizontal HTML tab and I want to hide the bottom border of the selected tab.

Here is the code I currently have - https://jsfiddle.net/vgx2k7p5/

This issue has been raised in discussions on Stack Overflow here and here

However, the solutions provided do not work for me as I am using a div structure without much JavaScript involved.

jQuery('.tab-links a').on('click', function(e) {

  var currentAttrValue = jQuery(this).attr('href');

  jQuery(currentAttrValue).show().siblings().hide(); //changed here
  jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
  e.preventDefault();
});
.tabs {
  width: 90%;
  margin: auto;
}
/*----- Tab Links -----*/

/* Clearfix */

.tab-links:after {
  display: block;
  clear: both;
  content: '';
}
.tab-links {
  margin: 0px;
}
.tab-links li {
  margin: 0px 3px;
  float: left;
  list-style: none;
}
.tab-links a {
  padding: 9px 15px;
  display: inline-block;
  border-radius: 3px 3px 0px 0px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  color: #999;
  transition: all linear 0.2s;
  border: 1px solid #fff;
}
.tab-links a:hover {
  text-decoration: none;
}
li.active a,
li.active a:hover {
  border: 1px solid #ccc;
  border-bottom: 1px solid #fff;
  color: #444;
}
/*----- Content of Tabs -----*/

.tab-content {
  padding: 15px;
  border-radius: 3px;
  border: 1px solid #ccc;
  background: #fff;
  min-height: 300px;
  z-index: -99;
}
.tab {
  display: none;
  min-height: 300px;
}
.tab.active {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="tabs margintop20">
  <ul class="tab-links">
    <li class="active"><a href="#tab1">PROFILE</a>
    </li>
    <li><a href="#tab2">REVIEWS</a>
    </li>
    <li><a href="#tab3">REWARDS</a>
    </li>

  </ul>

  <div class="tab-content">
    <div id="tab1" class="tab active clearfix">


    </div>

    <div id="tab2" class="tab">

    </div>

    <div id="tab3" class="tab">
      <h3>Videos and Screenshots</h3>

    </div>


  </div>
</div>

</div>

What could be the issue here? I've tried adjusting the z-index and border-bottom width without success.

Answer №1

I have made some changes to your css:

/* ADDED */
.tab-links .active{
    margin-top : 1px;
}
.active > a {
    margin-bottom: -1px;
}

After implementing these changes, the functionality seems to be working fine!


jQuery('.tab-links a').on('click', function(e) {

  var currentAttrValue = jQuery(this).attr('href');

  jQuery(currentAttrValue).show().siblings().hide(); //changed here
  jQuery(this).parent('li').addClass('active').siblings().removeClass('active');
  e.preventDefault();
});
.tabs {
  width: 90%;
  margin: auto;
}
/*----- Tab Links -----*/

/* Clearfix */

.tab-links:after {
  display: block;
  clear: both;
  content: '';
}
.tab-links {
  margin: 0px;
}
.tab-links li {
  margin: 0px 3px;
  float: left;
  list-style: none;
}
.tab-links a {
  padding: 9px 15px;
  display: inline-block;
  border-radius: 3px 3px 0px 0px;
  text-decoration: none;
  font-size: 16px;
  font-weight: 600;
  color: #999;
  transition: all linear 0.2s;
  border: 1px solid #fff;
}
.tab-links a:hover {
  text-decoration: none;
}
li.active a,
li.active a:hover {
  border: 1px solid #ccc;
  border-bottom: 1px solid #fff;
  color: #444;
}



/*----- Content of Tabs -----*/

.tab-content {
  padding: 15px;
  border-radius: 3px;
  border: 1px solid #ccc;
  background: #fff;
  min-height: 300px;
  z-index: -99;
}
.tab {
  display: none;
  min-height: 300px;
}
.tab.active {
  display: block;
}


/* ADDED */
.tab-links .active{
  margin-top : 1px;
  }
.active > a {
    margin-bottom: -1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="tabs margintop20">
  <ul class="tab-links">
    <li class="active"><a href="#tab1">PROFILE</a>
    </li>
    <li><a href="#tab2">REVIEWS</a>
    </li>
    <li><a href="#tab3">REWARDS</a>
    </li>

  </ul>

  <div class="tab-content">
    <div id="tab1" class="tab active clearfix">


    </div>

    <div id="tab2" class="tab">

    </div>

    <div id="tab3" class="tab">
      <h3>Videos and Screenshots</h3>

    </div>


  </div>
</div>

</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identifying Shifts in Objects Using Angular 5

Is there a way to detect changes in an object connected to a large form? My goal is to display save/cancel buttons at the bottom of the page whenever a user makes changes to the input. One approach I considered was creating a copy of the object and using ...

The pseudo element 'not' in CSS is currently not functioning as expected when applied to an anchor tag

When working with CSS, I encountered an issue while trying to apply a pseudo element on hover and active states of anchor tags. Unfortunately, my code was not producing the desired outcome. a:not(a[name="nobgcolor"]):hover{color:#ffff35;background-color:# ...

Choosing an element from an array in JavaScript that meets a certain criteria

How can I isolate an object from an array where the value for the "slug" key is "A"? For instance, consider the following data: var allItems = [ { "slug": "henk", "company_founded": "2008", "company_category": "Clean", ...

Creating a personalized notification box that is compatible with various screen sizes and web browsers on android devices with the help of

After successfully implementing a custom alert box to hide the header with JavaScript, I encountered an issue when trying to use it on different browsers and Android devices. The alert box appeared misplaced on the page and was too big for certain Android ...

Disable the javascript link on small devices

I currently have a javascript link (Trustwave) on my desktop website theme that I need to deactivate when viewed on mobile devices: Located in footer.tpl: <div style="position:absolute; margin-left:100px; margin-top:50px"> <script type="text/j ...

What is the best way to create a header that displays without the vertical scroll bar?

Is it foolish or out of the ordinary to ask a question without making an effort? I'm looking for a solution to have a header without a vertical scroll bar like in image 2 on the home page design. I want the top yellow header strip to be visible witho ...

How can I access an object from a JavaScript file within a Laravel blade template?

I am trying to implement the package Sortablejs in my blade file. After installing it with npm, I created a sortable.js file within my assets folder containing the following code: import Sortable from "sortablejs"; This file is compiled into th ...

Trouble arises when trying to combine NextJs 12.2.5 with next-auth 4.17 due to a dependency

npm ERROR! Could not find a solution for the dependency: npm ERROR! required peer next@"^12.2.5 || ^13" by [email protected] npm ERROR! in node_modules/next-auth npm ERROR! next-auth version is "*" as defined in the root project ...

What is the best way for OnSubmit to access an external file?

Recently, I adjusted this code snippet to include the onsubmit attribute with a validation function call. Instead of having the validate function within the same file, I moved it to an external file for better organization. Now, I am wondering how do I e ...

How can I dynamically update HTML content in React upon receiving an AJAX response?

Hi there, I'm new to using React and I have a requirement where I need to make an AJAX GET request to the server when a user clicks on a button. Based on the received response, I need to prepare HTML and display it. I tried implementing this with the ...

Tips and Tricks for Resizing Images within an Angular iframe

Can anyone help me figure out how to make the image content inside my iframe fit perfectly within the frame? I noticed that when displaying a PDF it scales correctly, but when displaying a PNG image it does not scale properly and looks distorted. Any ass ...

JavaScript Tab Fade Effect

I have a tab system that utilizes JavaScript to switch tabs. I am trying to implement a fade in and out effect when switching tabs. The current JavaScript simply adds or removes the clicked tab selected by the user. I have managed to partially achieve the ...

What are the potential risks associated with including your backend server port number in your code?

Working on a project using React and Node.js here. My server is set up with Express and the dotenv package to keep my server configurations secure, like the PORT number where my backend server operates. For instance, my server's environment variable i ...

Are there any conventional methods for modifying a map within an Aerospike list?

Attempting to modify an object in a list using this approach failed const { bins: data } = await client.get(key); // { array: [{ variable: 1 }, { variable: 2 }] } const { array } = await client.operate(key, [Aerospike.maps.put('array', 3).withCon ...

How can I implement word-breaking in HTML code?

Is there a way to insert a line break in the second TD tag of this HTML code below after a certain width is reached? <tr class="odd"> <td><b>Reason for Termination:</b></td> <td>this has bunch of reasons like re ...

Background operations for keyboard shortcuts/hotkeys implemented in JavaScript

Is it possible to access keyboard shortcuts even when my tab is not selected? I'm looking to be able to use "push-to-talk" functionality without having the tab actively in focus. Would this require permission like the fullscreen APIs do? Essentially, ...

Tips on transforming JSON into nested JSON using parent_id as a reference

In the given JSON array, each object contains properties 'is_parent' and 'parent_id'. If an object has children objects, its 'is_parent' property is set to 1, otherwise it is set to 0. let list = [ {id: 4, name: 'dd&a ...

Is it possible to have the website show up at a default size of 90% on the display

My preference is for my website to appear at 90% instead of 100%. This seems to be a common occurrence for me. Is there a way to have it default to this appearance? ...

Smoother transitions with spline curves in Three.js

My current project involves drawing a CubicBezierCurve3 curve in three js. However, I want to enhance the drawing process by visualizing it as a moving rocket leaving behind a gas trail. Rather than having the entire curve drawn at once, I aim to draw it p ...

Display the console.log output of NodeJs on an HTML webpage

I've set up a server named app.js and have multiple clients connecting to it. Currently, I am displaying the server's messages to the client in an HTML page called index.html. However, I also want to display the messages from the clients to the s ...