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

Ways to compare UTC timestamps using JavaScript

Insight into Time Data I have obtained UTC start and end times from a database query, which are stored in an array format as follows: [ '9145001323', '08:00', '12:00' ] The second and third elements in the array indicate t ...

Experiencing difficulties with Magento operations

Currently facing an issue while attempting to set up Magento on my server. I have transferred all files from another server to mine, but now encountering an error. Could this be related to the symlinks I generated or is it caused by something else? Encoun ...

Streaming video to multiple clients concurrently using NodeJS

We are currently facing an issue with serving a video stream. Due to the fact that HTML5 video tag does not support udp to multicast, we have been attempting to repurpose an existing ffmpeg stream and broadcast it to multiple responses. Unfortunately, thi ...

Google Maps is experiencing difficulties maintaining its longitude and latitude coordinates within the Bootstrap tabbed user interface

I implemented ACF's Google Map to display a map on my webpage. I followed the instructions closely and made some minor modifications to the map js for styling purposes. One key change I had to make was in this section to ensure the map loads correctly ...

Attempting to select an image with the intention of triggering a modal to appear through an ajax

Hi there, I recently started coding and I'm facing an issue that I can't seem to solve. I want to set it up so that when you click on an image, a modal opens corresponding to the img tag, and then the modal click event triggers a method. The prob ...

Can JavaScript bypass the need for an html page and go directly to the printing process?

Is it possible for a user to click a "print" button and have the printer start printing? Please note that there is already a server process in place (via AJAX) that can respond with success for printing or return HTML content for display, so that is not a ...

Optimizing HTML/CSS performance: Comparing flexbox and tables for handling extensive datasets

Creating a React table component with hundreds of lines and variable cell widths can be complex. Would it be better to implement this using flexbox or a traditional table structure in HTML/CSS? ...

Creating a Striking Multi-Layered CSS Header

Can someone help me figure out how to add horizontal lines behind the words in this header? Here is what I have so far: . However, I want to achieve something similar to this design: . You can view my progress on JSFiddle here: https://jsfiddle.net/n2tst0b ...

Bootstrap form toggle switch component for ReactJS

I'm having trouble figuring out why the default value for my react-bootstrap switch won't set to false (off). It seems like the only way it changes is when I trigger the onChange event handler. Am I overlooking something? Below is the section of ...

Separate modules in the Webpack.mix.js file don't produce any output files in the public folder

I've recently been tackling a Laravel project with an extensive webpack.mix.js file residing in the root directory, boasting nearly 5000 lines of code. In an effort to enhance organization and maintainability, I've opted to break it down into ind ...

Connecting the value of one input to influence another input

There are two input boxes provided - one for current address and another for permanent address. When the checkbox is clicked, the value of the current address should be displayed in the permanent address box. However, I am facing an issue where when I unc ...

How does the single-threaded nature of Node.js handle an abundance of concurrent requests?

I'm currently delving into the world of nodejs, trying to wrap my head around its single-threaded nature. Here's a pondering I have: Let's say I implement a non-blocking method and we have 20000 concurrent requests flowing in. If one request ...

The CKEditor is having trouble properly opening code snippets

I have been using ckeditor 4.4 along with the code snippet plugin. Initially, when I create a document with a rich code snippet and save it, everything works perfectly fine. The source code for what is generated looks like this: <pre><code>&am ...

Is the CSS scale activated by mouseover or click?

My CSS code successfully scales images, but the issue is that it affects every image on the page. I am looking for a solution to apply this CSS only when the user hovers over or clicks on an image. The challenge is that images are added by non-technical w ...

Set a div to have both absolute positioning and sticky behavior

Looking to create a div ("profilemenu") that pops out on the right side of the page triggered by a button (I'll handle this part). I want it to have a sticky attribute, but positioning has been tricky. Using position: absolute works for proper placeme ...

Tips for arranging letters on separate lines using CSS

I have a set of four divs that display numbers, and I want to show the corresponding words below each number. Despite trying to use the p tag with white-space: pre; in CSS, I have not been successful: #c { padding-top: 30px; padding-bottom: 30px; } ...

Listening for position changes using jQuery events

It is essential to be able to track the relative position of elements, especially when dealing with dynamic layout issues. Unfortunately, there are no built-in options in CSS to listen for changes in position() or offset() attributes. Reason: Changes in a ...

Exploring JSON data structures using autocomplete functionalities

Here's the code I'm working with: <s:hidden id="s" value="%{Users}"/> The variable Users contains an array list of User objects. This code is written in Javascript. I want to access Users as JSON for auto-complete functionality: var valu ...

Trying to call an applet method using JavaScript will not be successful

When trying to invoke methods of a Java applet using JavaScript, I encounter an issue that requires the site to be added to trusted sites and security set to low in order for it to work properly. Otherwise, an error is thrown: Microsoft JScript runtime ...

The Next.js page suddenly disappears after a moment

Out of the blue, my next.js page suddenly went blank for no apparent reason. I didn't make any changes, it just happened. I attempted to restart my dev server and even deleted the '.next' folder, but nothing seemed to fix the issue. Despite ...