"Troubleshooting vertical tab inconsistencies in Jquery: addressing unexpected gaps and alignment

After spending a considerable amount of time on this, I'm still struggling to make it work properly.

The main issue is the gap between the tabs and the content area. I've tried adjusting the positioning, but it ends up affecting the overall layout in a negative way.

https://i.sstatic.net/mIHX7.png

Additionally, the alignment of the tabs with the content seems off. Currently, I have set the tabs to left: -80px; to separate them from the content. However, this causes problems depending on the user's screen size.

https://i.sstatic.net/C9HwE.png

If anyone has any suggestions or solutions for these issues, I would greatly appreciate it!

I've created a JSFiddle for testing purposes.


var tabTitles = ["First Tab", "Second Tab", "Third Tab", "Fourth Tab", "Fifth Tab", "Sixth Tab"];

$(".tabHeader").click(function() {
  $(".tabHeader").removeClass("active");
  var position = $(this).position();
  var top = position.top;
  $(".active").css("top", top);
  $(this).addClass("active");
  var text = $(this).text().trim();
  switch (text) {
    case "Tab 1":
      $(".tabTitle").text(tabTitles[0]);
      break;
    case 'Tab 2':
      $(".tabTitle").text(tabTitles[1]);
      break;
    case 'Tab 3':
      console.log('yo');
      //$('.textBody').html('TEST!');
      $(".textBody").load("https://raw.githubusercontent.com/jiahaog/ajax-test-page/master/index.html", function(responseTxt, statusTxt, xhr) {

      });
      $(".tabTitle").text(tabTitles[2]);
      break;
    case 'Tab 4':
      $(".tabTitle").text(tabTitles[3]);
      break;
    case 'Tab 5':
      $(".tabTitle").text(tabTitles[4]);
      break;
    case 'Tab 6':
      $(".tabTitle").text(tabTitles[5]);
      break;
    default:
      $(".tabTitle").text("Select A TAB");
      break;

  }
});
            

body {
  background-color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  font-size: 12px;
}

.card {
  display: flex;
  flex-direction: row;
  background-color: white;
  margin: 0 auto;
  margin-top: 10px;
  width: 85%;
  height: 100%;
  box-shadow: 1px 2px 6px #d3d3d3;
  border-radius: 4px;
}

.tabHeader {
  width: 80px;
  height: 50px;
  background-color: #47bc8b;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}
.verticalTabs {
  position: relative;
  left: -80px;
  right: 0px;
  display: table-cell;
}

.active {
  position: relative;
  z-index: 50;
  width: 80px;
  height: 50px;
  background-color: #259162;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}

.tabText {
  position: absolute;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  font-size: 12px;
  margin-top: 16px;
  margin-left: 23px;
}

.textHolder {
  margin: 10px;
  text-align: justify;
  overflow: scroll;
  overflow-x: hidden;
  width: 100%;
}

.tabTitle {
  font-size: 20px;
  font-weight: 600;
  padding: 0 0 20px 0;
}
            
<div class="tab-wrapper">

  <div class="card">
    <div class="verticalTabs">
      <div class="tabHeader active">
        <div class="tabText">Tab 1</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 2</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 3</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 4</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 5</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 6</div>
      </div>
    </div>
    <div class="textHolder">
      <div class="tabTitle">First Tab</div>
      <div class="textBody"></div>
    </div>
  </div>

</div>
            

Answer №1

To simplify the structure, you can transfer the border-radius and box-shadow properties from .card to .textHolder. Additionally, instead of using positioning in .verticalTabs, it is recommended to utilize padding for spacing between .card and .textHolder.

var tabTitles = ["First Tab", "Second Tab", "Third Tab", "Fourth Tab", "Fifth Tab", "Sixth Tab"];

$(".tabHeader").click(function() {
  $(".tabHeader").removeClass("active");
  var position = $(this).position();
  var top = position.top;
  $(".active").css("top", top);
  $(this).addClass("active");
  var text = $(this).text().trim();
  switch (text) {
    case "Tab 1":
      $(".tabTitle").text(tabTitles[0]);
      break;
    case 'Tab 2':
      $(".tabTitle").text(tabTitles[1]);
      break;
    case 'Tab 3':
      console.log('yo');
      //$('.textBody').html('TEST!');
      $(".textBody").load("https://raw.githubusercontent.com/jiahaog/ajax-test-page/master/index.html", function(responseTxt, statusTxt, xhr) {

      });
      $(".tabTitle").text(tabTitles[2]);
      break;
    case 'Tab 4':
      $(".tabTitle").text(tabTitles[3]);
      break;
    case 'Tab 5':
      $(".tabTitle").text(tabTitles[4]);
      break;
    case 'Tab 6':
      $(".tabTitle").text(tabTitles[5]);
      break;
    default:
      $(".tabTitle").text("Select A TAB");
      break;

  }
});
body {
  background-color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  font-size: 12px;
}

.card {
  display: flex;
  flex-direction: row;
  background-color: white;
  margin: 0 auto;
  margin-top: 10px;
  width: 85%;
  height: 100%;
}

.tabHeader {
  width: 80px;
  height: 50px;
  background-color: #47bc8b;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}

.verticalTabs {
  position: relative;
  display: table-cell;
}

.active {
  position: relative;
  z-index: 50;
  width: 80px;
  height: 50px;
  background-color: #259162;
  -webkit-transition: all .3s ease-in-out;
  transition: all .3s ease-in-out;
}

.tabText {
  position: absolute;
  color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  font-size: 12px;
  margin-top: 16px;
  margin-left: 23px;
}

.textHolder {
  padding: 10px;
  text-align: justify;
  overflow: scroll;
  overflow-x: hidden;
  width: 100%;
  box-shadow: 1px 2px 6px #d3d3d3;
  border-radius: 4px;
}

.tabTitle {
  font-size: 20px;
  font-weight: 600;
  padding: 0 0 20px 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="tab-wrapper">

  <div class="card">
    <div class="verticalTabs">
      <div class="tabHeader active">
        <div class="tabText">Tab 1</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 2</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 3</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 4</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 5</div>
      </div>
      <div class="tabHeader">
        <div class="tabText">Tab 6</div>
      </div>
    </div>
    <div class="textHolder">
      <div class="tabTitle">First Tab</div>
      <div class="textBody"></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

The date in the JSON response does not align correctly

Seeking insights into this issue, I am currently utilizing the code below to generate a JSON response through an AJAX request console.log('get_therapist_sessions', response); response.forEach(function(item){ console.log(item); ...

The CSS descendant selector does not seem to be functioning properly with the focus state on iOS

In order to display content using the :focus state when the parent element has focus, I have used the following CSS code: .child { display: none; } .parent:focus .child { display: block; } It's important to note that the parent element has tabindex= ...

The value is currently unset in the TypeScript language

The variable `this.engenes_comparte` is showing up as undefined inside the subscribe function, but it works fine outside of it. baja(){ this._restService.getEngines(this._globalService.currentFisherMan.nid).subscribe((data : any[]) => { le ...

Ways to transmit the current page number and length to the server

After diligently following the DataTable documentation, I managed to implement the code below, which successfully renders data but encounters issues with pagination. How can I retrieve the actual pageNumber (table.page.info().page) when clicking on a page ...

displaying and concealing elements with jquery

Is there a way to hide a div if the screen size exceeds 700px, and only show it when the screen size is less than 700px? Below is the jQuery code I'm attempting to use: jQuery(document).ready(function() { if ((screen.width>701)) { $(" ...

The utilization of angular2-materialize is not possible due to an error message indicating that jQuery.easing is undefined

Greetings to all who are taking the time to read this. I am encountering an issue while trying to run ng serve. Here is the error message I am receiving: TypeError: jQuery.easing is undefined Here is a breakdown of what I have done so far: ng new X cd X ...

Cache application

Experimented with the following code snippet from w3schools: Coding in index.html <!DOCTYPE html> <html manifest="demo_html.appcache"> <body> <script src="demo_time.js"></script> ...

What is the best way to center a rotated element and have it aligned to the top?

* { box-sizing: border-box; } body { font-family: 'Poppins', sans-serif; margin: 0px; } .we-adopt { background-color: #8a8484; color: #ffffff; padding: 88px 0px; height: 100px; } .we-adopt-list span { display: i ...

Issue: attempting to write after the end of a node

Currently, I am using the stream() function from https://www.npmjs.com/package/cassandra-driver to read data from Cassandra. I am listening for events and piping the stream to the response object; however, I encountered an error: Error: write after end T ...

A step-by-step guide to thoroughly examining the form status in a React application, allowing for the activation of a previously disabled submit button

When I have an onChange event in React, the state is populated correctly. I disable the form button when a field is empty on submit, but I also want users to be able to go back and fill out those fields. The key issue is that if both fields have data, I wa ...

Encountered an issue when utilizing Yahoo PlaceFinder API and jQuery to retrieve data in json format

Currently, I am integrating Yahoo API into my project. Initially, working with the Yahoo GeoPlanet in json format using jQuery was a seamless process. However, I have encountered issues while trying to implement the Yahoo PlaceFinder API with jQuery in jso ...

Vue alert: Component resolution failed while attempting to create a global component

I am new to Vue Typescript and I have been encountering an issue while trying to create global components. I received a warning and the component did not load on the template. Here is how I attempted to create global components: App.vue import { createApp ...

Customizing the appearance of Indicators and Paginator in PrimeNG Carousel

I have integrated a carousel using PrimeNG which has the following design here Take note of the style of the carousel indicators and navigators. I want to achieve the default style of indicators/navigators for the carousel as shown here I have included t ...

Implementing a Custom HTML Attribute to the Script Tag in Vue JS

I have decided to switch from using Google Analytics to Plausible analytics for my website. However, I am encountering an issue with adding the Plausible script to the head of my Nuxt JS document. I have created a custom plugin to handle this, but the Vue ...

Updating database records seamlessly without the need to reload the page

I am attempting to update my database without having to refresh the page. Here is the code I am using: // Submit code to the database $(document).on("click", "#pin", function(){ $.post( $("#myForm").attr("action"), $("#myForm").serialize(), funct ...

Regular expressions are compatible with JavaScript, but unfortunately, they are not supported

After successfully implementing this regex in my JavaScript for webpage validation, I attempted to incorporate it into my PHP script as a backup. However, every string I passed through the regex failed, even correct names. In an effort to resolve the issu ...

Handling a JSON array error when working with a JSON string field

Attempting to create a JSONArray object with nested arrays and json strings, specifically looking at the "res" field. [{ "time": 123813213, "value": [{ "name": "task", "res": "{\"taskName\" : \"NAME\", \"ta ...

What is the best way to iterate through an ID using jQuery?

After pulling the list of doctors in my area from the database and displaying it on my webpage, I now want to load each doctor's "About" content inside a Bootstrap modal. I added an "about" column within the same database table where the doctors' ...

Challenger arises in the realm of Chakra UI styling

Recently, I've encountered an issue with displaying a card using chakra UI and next js. The CSS of chakra UI seems to be messed up, causing all my components to display incorrectly. It was working perfectly fine until yesterday. I tried deleting the . ...

JavaScript Date displaying the string in the format YYYY/MM/DD HH:MM

I'm struggling to figure out how to format a date and time string like this: "YYYY-MM-DD-HH-MM" Can anyone help me with this? Here is the code I currently have: var x = new Date(); var formattedTimeStamp = x.toString(); Current Output: Tue Oct 3 ...