Remove the bottom border from the active tab by utilizing the <div> and <a> elements

I am facing an issue with a tabbed menu on my webpage. While the menu is functioning correctly, I am struggling to remove the bottom border from the active tab.

You can view all of my test code here.

While I have come across solutions using <ul> and <li> for creating tabs, my implementation relies on <div> and <a> tags. The solutions provided for list tags do not seem to work in this case.

Currently, my code appears like this: https://i.stack.imgur.com/RL3bo.png

However, I want it to resemble more like this:

https://i.stack.imgur.com/Fwobz.png

Any guidance would be appreciated. Thank you.

Answer №1

If you want to avoid using border-bottom on your .tab bar (which will position the border line below your tabs), you can utilize a pseudo element to place the line underneath your tabs so they blend in with their white background. Check out the live demo below.

(I've included your code within Stack Overflow and made some modifications. Remember to provide all code in your question instead of linking to an external source next time.)

/* Styling for the tab */

div.tab {
  overflow: hidden;
  background-color: #fff;
  position: relative;
}

/* Custom styling for the bottom border */

div.tab::before {
  content: '';
  background-color: #ccc;
  height: 1px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

/* Styling for the buttons inside the tab */

div.tab a {
  float: left;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  transition: 0.3s;
  position: relative;
}

/* Changing background color of buttons on hover */

div.tab a:hover {
  background-color: #ddd;
}

/* Defining an active/current tablink class */

div.tab a.active {
  background-color: #fff;
  border-top: 3px solid rgb(30, 18, 197);
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
}

/* Styling for the tab content */

.tabcontent {
  display: none;
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-top: none;
}
<script src="https://thimble.mozilla.org/resources/remix/index.js" type="text/javascript"></script>

<div class="tab">
  <a class="tablinks" onclick="openCity(event, 'London')">London</a>
  <a class="tablinks" onclick="openCity(event, 'Paris')">Paris</a>
  <a class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</a>
</div>

<div id="London" class="tabcontent">
  <h3>London</h3>
  <p>London is the capital city of England.</p>
</div>

<div id="Paris" class="tabcontent">
  <h3>Paris</h3>
  <p>Paris is the capital of France.</p>
</div>

<div id="Tokyo" class="tabcontent">
  <h3>Tokyo</h3>
  <p>Tokyo is the capital of Japan.</p>
</div>

<script src="https://thimbleprojects.org/soopergenius/365314/scripts.js" type="text/javascript"></script>

Answer №2

A quick and simple solution:

delete the following line from div.tab{

border-bottom: 1px solid #ccc;

remove this line from .tabcontent

border-top: none;

insert these lines into .tabcontent

border-top: 1px solid #ccc;
margin-top: -1px;

lastly, include this line in div.tab a.active

border-bottom: 1px solid #fff;

Answer №3

To create a unique effect, you could try positioning the tab so that it overlaps the <div> below it. Make sure to set the active tab's class to position:absolute and adjust the height of the tab to prevent the side borders from interfering with the content below. This technique was quickly developed using the Chrome console, so make sure to thoroughly test it within your design.

https://i.stack.imgur.com/vh8IP.png https://i.stack.imgur.com/71yKX.png

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

What is the best way to generate an array from JSON data while ensuring that the values are not duplicated?

Upon receiving a JSON response from an API, the structure appears as follows: { "status": "success", "response": [ { "id": 1, "name": "SEA BUSES", "image": null }, { "id": 2, ...

`Is there a way to modify the attribute text of a JSON in jQuery?`

I'm attempting to modify the property name / attribute name of my JSON object. I attempted it like this but nothing seems to change. After reviewing the input JSON, I need to convert it to look like the output JSON below. function adjustData(data){ ...

Incorporate an external CSS file programmatically

Can I apply the SomeStyle.css CSS file to an aspx page from its code behind? ...

What is the reason for Firefox displaying the "excessive recursion" error message?

I have been working on generating an area Google chart using the code below, but I am running into an issue where Firefox is showing me a "too much recursion" error. The chart currently only has one point for testing purposes. Can anyone provide some gui ...

Creating a multi-page app using React: A comprehensive guide

I am in the process of developing an application using NodeJS, and I have decided to incorporate React for creating interactive components within the app. However, my goal is to avoid turning it into a single-page application. How can I effectively distri ...

Using Angular to fetch API response and convert it into a promise

I've been following the Angular tutorial available at https://angular.io/tutorial/toh-pt6. The tutorial demonstrates how to retrieve a Json response from an API call and then match it to a promise. One specific example from the tutorial is as follows ...

Is there a way to automatically change specific characters as a user types in an input field?

I'm facing an issue with replacing some characters dynamically. The goal is to ensure that user-input text is URL-friendly for constructing a URL: function slugify(string) { const a = "àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïí ...

Is it possible to display a title tooltip only when the CSS ellipsis feature is active in a React component?

Issue: I am trying to find a neat solution to display a title tooltip on items that have a CSS ellipsis applied, within a React component. Approaches Attempted: I created a ref, but it only exists after componentDidUpdate. Therefore, I force an update w ...

How can JavaScript effectively retrieve the JPEG comment from a JPEG file?

How can one properly retrieve the JPEG comment field (not EXIF, but the COM field) from a JPEG file using JavaScript, particularly when running node on the command line? While there are several libraries available for reading EXIF data in JavaScript, I ha ...

"Using the selected option from a dropdown list to pass to a PHP file for autocomplete functionality

Although there is no error in the code, I am facing an issue where, after selecting an option from the brands dropdown, when I type in the product field, it passes "%" instead of the brand id (1, 2, or 3). Is there a way to modify the code so that it passe ...

Utilizing PHP to send arrays through AJAX and JSON

-I am facing a challenge with an array in my PHP file that contains nested arrays. I am trying to pass an integer variable (and may have to handle something different later on). -My objective is to make the PHP file return an array based on the incoming v ...

How to eliminate blinking in Ajax refresh upon successful completion

I have come across this issue, and although I've checked out a solution on Stack Overflow (ajax refresh - how to remove the blinking), it hasn't resolved my problem. Is there a way to prevent the page from blinking every 3 seconds when the Ajax ...

Error in JScript encountered during the downgrade to .NET Framework 2.0

Working on a Web Application project has brought about some challenges for me. Originally created in .NET 3.5, I recently found out that it has to be converted to .NET 2.0 (sigh). This transition not only caused issues with the LINQ functionalities but als ...

How to incorporate material-ui tabs in nextjs framework?

I'm currently working on a project using material-ui, nextjs, and typescript. My main focus right now is getting the navbar to function properly within nextjs: import * as React from 'react'; import AppBar from '@material-ui/core/A ...

The JSON response from Ajax is not coming back as anticipated

My attempts to make a basic ajax call are failing; var getPrevious = function(){ console.log('ajaxing'); $.ajax({ type: 'GET', dataType: "json", url: 'http://'+DOMAIN+'/previous', ...

Is it possible to enclose an image with two <div> tags in a single line?

Can anyone help me with this layout issue I am facing? I have two <div>s wrapping an image in the same row, but for some reason, the right <div> keeps dropping below. I've attempted using float, display:inline-block, and tweaking the styl ...

Increasing box width in Django

I'm currently working on a website using Django all-auth for authentication. Everything is functioning perfectly, but I'm wondering if there's a way to increase the size of the username and password input boxes using HTML. Below is the code ...

Printing in ASP.Net without displaying a dialog box

Is there a way for my web application to automatically print a popup page without prompting the client to choose a printer? I am looking for guidance on implementing silent printing in ASP.Net using java-script or ajax, or any other suitable solution for ...

Obtaining the attribute value of a disabled element in an Angular JS application

Currently, I am struggling to retrieve the attribute value of a disabled element during runtime and then assert its value. The code I'm using is not providing the desired result: softAssert.assertFalse(shrSub.nextButton().waitForPresent().getAttribu ...

Crystal Reports does not recognize or integrate HTML elements

Despite entering HTML text on the field: https://i.sstatic.net/vyvQ2.png Even though I am using valid tags as explained in this resource: What HTML tags are supported in Crystal Reports 2008, my report is not generating HTML but only displaying the tags ...