Tab containers do not adjust their height according to the size of their content

My tabs are filled with text, but I'm having trouble adjusting the height using either height:auto or height:100%. When using px, it works fine but restricts the tab from expanding when there is a lot of text.

This is the CSS code I am currently using:

.tab-section {
    float: left;
    width: 100%;
    height: 792px;
    margin-bottom: 25px;
} 

Is there a way to make the height be auto regardless of the amount of text?

Answer №1

The reason for the distorted layout is due to placing the tab-content within the li element, which is typically used for menus.

To resolve this issue, move the tab-content outside of the tab-section. Additionally, ensure that elements are properly floated (for instance, if the parent has float: left, the child should also have float: left to maintain proper alignment).

Answer №2

.tab-content styled with position:absolute

Inspired by the solution provided by feeela

Elements positioned absolutely are taken out of the normal flow, which means they do not affect other elements. This makes it challenging to adjust the height of parent elements based on an absolutely positioned element.

To address this issue, you can use the following script:

$("[type = radio]").click(function () {
    var oh=$(this).parent().find(".content").outerHeight();    
    $(".tabs").height(oh);
});

Check out the live demo on Fiddle

Alternatively, you can leverage viewport units(vh) or calc() for proper sizing of ul.tabs (css3)

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

Implementing Table Updates in Yii2 using Ajax Calls

I've developed a JavaScript script and Controller Action to update a field when a button is clicked as shown below. Although I receive a success response, the table does not get updated. public function actionSetstarttime() { if (Yii ...

How can the resize function be modified to include an additional 100 pixels on top of the current size?

Something interesting I discovered is that I can do the following: height() + 100); When I attempted to execute: $('.modal1').colorbox.resize({height()+100}); I was puzzled as to why it didn't work. All I wanted to achieve is to add an ad ...

Tips for organizing a div into a dock panel

I am seeking guidance on how to align and resize the following divs based on my specific requirements outlined below. Area A Area A should remain at the top with a set height that will not change. Area B The height of Area B should vary between 0 and a m ...

Freezing browser during an active AJAX call

I am currently working on an ASP.NET Web App and have noticed a peculiar issue. Whenever I make a simple ajax call (as shown below), the web application becomes unresponsive to any actions I try to perform on a different browser. $.ajax({ type: "G ...

An issue arose in Leaflet where drawing on the map became impossible after making an update to a marker's position

I have been working with Leaflet, Leaflet-draw, and Cordova Geolocation. Initially, when the map is loaded in globe view, drawing works perfectly. However, when the locate function is called to update the map center and marker position, drawing becomes imp ...

Transferring the chosen dropdown value to the following page

I am attempting to transfer the currently selected value from a dropdown to the next page using an HTTP request, so that the selected value is included in the URL of the subsequent page. The form dropdown element appears as follows: <form name="sortby ...

Dealing with Issues in Projectile Image Display: Solutions for Resolving the Error

I've been attempting to change my projectile from circles to images, but I'm encountering this error File "C:\Users\Habib\Desktop\PYTHONGGAME\py.py", line 353, in <module> bullets.append(projectile(round(player ...

Monitor the Size of the Element while Utilizing jQuery's Animation Feature

When animating the width of an HTML element using jQuery's "animate()" function, how can I dynamically keep track of the increasing width? For example, if I have an HTML element with CSS set to 'div {width: 10%;}' <div></div> &l ...

Having trouble getting CSS animation to work on Mozilla using mozAnimationName?

<style> @keyframes shake { 0% { -moz-transform:scale(0);opacity:0; } 25% { -moz-transform:scale(1.3);opacity:1; } 50% { -moz-transform:scale(0.7);opacity:1; } 75% { -moz-transform:scale(2); ...

Is writeConcern not being returned by MongoDb's deleteOne function?

I have a function that deletes a specific document in MongoDb based on an id match. Below is the code snippet. deletePoll: function(db, user_id, callback) { db.collection('polls').deleteOne({ _id: user_id }, ...

Horizontal Accordion Design for Cascading Style Sheets (CSS) Books

I am currently working on developing a page that features a book layout. This page will include tabs that users can expand individually. If you would like to see a working example, you can check out this link: https://codesandbox.io/s/book-layout-l28gh?fi ...

react component fails to rerender upon state change

I am struggling with a React functional component that includes a file input. Despite selecting a file, the text in the h1 tag does not change from choose file to test. The handleChange function is triggered successfully. A console.log statement confirm ...

Guide to stacking blocks on top of each other

How can I create even spacing between blocks of different heights? For instance, in the image below, you can see that block 2 should be positioned directly under block 1. https://i.stack.imgur.com/RnYbP.png https://i.stack.imgur.com/LHvlz.png ...

Ways to prevent this column from taking up vertical space

When in desktop mode, I am facing an issue where the image is creating a gap between the "full name" and "Form Number" columns. Is there a way to adjust it so that the full name column starts right below the form number column? I know I could simply place ...

Showcasing XML data from a GET request with the help of JQUERY

My task was to ensure that the code runs without any errors, but now I'm facing an issue where no data is being displayed. The output appears blank even though I followed a tutorial carefully. There are no visible errors and I have double-checked all ...

Unable to find the specified element within the dropdown menu

Trying to figure out how to distinguish my xpath from the following: <td onclick="hrefClick(this,4,0);" onmouseout="menuLevel2MouseOut(this);" onmouseover="menuLevel2MouseOver(this);" style="padding-left:30px; padding-top:10px; padding-b ...

Table with a dynamic image background that seamlessly adjusts to full width while maintaining its original aspect ratio

I am currently facing an issue with a table that has a background image. I want the background image to span 100% of the width of the div container and automatically adjust its height while maintaining its aspect ratio. #pitch{ background-color: d9ffd9 ...

Adding a text field dynamically with angular2 can be achieved by using Angular's `

Hey everyone, I'm currently working on a project using angular2 and I've been attempting to dynamically add an input text field. It seems to be working fine but here's the code snippet: Typescript (TS): initArray() { return this._fb.gr ...

Change the Vue3 PrimeVue theme or CSS file with a simple click or upon page load

One way to incorporate themes is by importing them in the main.js file at the root of the app: import 'primevue/resources/themes/arya-orange/theme.css'; However, I am exploring ways to dynamically switch CSS files based on the user's system ...

Utilizing slug URLs effectively in Next.js

In my current project with Next.js, I am working on implementing "dynamic routes". The goal is to update the URL structure such that upon clicking, the URL should look like "myurl.com/article/55". To achieve this, I have utilized the following "link tag": ...