I'm currently in the process of designing unique tabs, however, the content within the tabs

My current project involves creating tabs where all the tab content is inside one div with a position:relative, and each content div has been given a position:absolute.

The issue I'm facing is that when the position is set to absolute, the content overlaps the footer.

I am aware that I can use min-height on the relative div, but I am seeking a more suitable solution. The code snippet below illustrates what I have in mind:

I need the height of the relative div to adjust based on the inner content's height.

.rel{min-height:300px; height:auto; background:red; width:100%; position:relative;  }

.abs{position:absolute; top:0; left:0; height:100%; width:100%; background:#eee; }
<div class="rel">
    <div class="abs"> </div>
    <div class="abs">4</div>
    <div class="abs">3</div>
    <div class="abs">2</div>
    <div class="abs">
        <p>
            When it comes to web design services, we are a top rated player with stunning capabilities that will immensely benefit every business. As we are a well experienced and highly skilled web design company, a lot of businesses bank on us for their affordable web design requirements. We provide a number of affordable web design packages and low cost web designing quotes for any of your requirements and preferences. Therefore a lot of businesses find it very convenient to work with us to avail of some profitable custom website design packages. Hence a huge customer base considers us the top web design company for small businesses.

            WordPress is a highly popular platform for different kinds of web development projects. This open source platform provides a host of benefits to the designers and businesses. As a WordPress website development company we provide our clients with the complete suite of WordP...
        </p>
    </div>
</div>

Answer №1

While some may view this method as unconventional, it actually gets the job done without the need for Javascript or complex calculations, so I decided to share it here.

The visual outcome in the example may appear a bit peculiar due to the tabs being semi-opaque, allowing you to see how they interact (or don't) and overlap each other.

The technique involves stacking all elements on top of one another without utilizing absolute positioning, enabling the parent element to automatically adjust its height accordingly. To achieve this effect, I followed these steps:

  • Displayed all tabs as inline-block elements to form a linear layout.
  • Prevented the line from wrapping by applying white-space: nowrap to the parent element. To ensure proper text rendering inside the tabs, I reset the white space with white-space: normal.
  • Assigned a negative right margin of -100% to each block, causing them to behave as if they have zero width in relation to the next block's position. This results in subsequent blocks starting at the same left position.
  • Included specific styling adjustments such as setting the font size to 0 on the parent element to eliminate whitespace issues. Alternatively, any extra spaces between tab divs in the HTML code can also address this concern.

I opted to include <p> tags within each tab to maintain consistent behavior across all tabs and avoid comments like "Hey! Tab 2 seems higher!"

The necessary CSS for this approach is relatively minimal. I segmented it with comments for easy removal of unnecessary parts.

Regarding the naming convention, I deliberately retained the identifiers rel and abs. Renaming them would have required considerable effort, demonstrating that using descriptive names related to function (tab-container, tab-sheet) is preferable over specifying implementation details. ;-)

/* Basic alignment settings */
.rel{
  white-space: nowrap;
}

.abs{
  vertical-align: top;
  white-space: normal;
  display: inline-block;
  width: 100%; 
  margin-right: -100%;
}

/* Resolve white-space issues that could affect tab positioning.
  Can be mitigated by removing excess whitespaces in the HTML content, rendering this CSS redundant. */
.rel{
  font-size: 0;
}

.abs{
  font-size: 1rem;
}

/* Additional styles for demo purposes */
.rel {
  box-sizing: border-box;
  border: 1px solid red;
}

.abs {
  opacity: 0.5;  
  background: #eee; 
  
  box-sizing: border-box;
  border: 1px solid blue;
}

.abs:nth-child(1) { color: red; }
.abs:nth-child(2) { color: grey; }
.abs:nth-child(4) { color: green; }
.abs:nth-child(5) { color: blue; font-weight: bold; }
<div class="rel">
    <div class="abs intro"><p>First tab, positioned at the bottom and nearly invisible</p></div>
    <div class="abs"><p>2</p></div>
    <div class="abs"><p>3</p></div>
    <div class="abs about-us">
        <p>
            When it comes to web design services, we are a top-rated player with remarkable capabilities that greatly benefit businesses. Our extensive experience and high-level skills make us a preferred choice for affordable web design solutions. We offer various budget-friendly packages tailored to your needs and preferences, making it convenient for many businesses to work with us for customized website designs. Our large customer base recognizes us as a leading web design company for small businesses.

            WordPress remains a popular platform for diverse web development projects, offering numerous advantages to designers and businesses. As a WordPress website development company, we provide comprehensive WordPress services backed by accomplished and talented web designers. Feel free to inquire about our competitive WordPress website design pricing. Benefit from our exceptional expertise in WordPress development to create stunning websites.

            In the realm of Ecommerce Web Design Services, we excel in designing responsive websites that perform exceptionally across various interfaces. Each project showcases our creativity and commitment to delivering top-notch designs. Beyond web and ecommerce service offerings, we specialize in several other areas to serve clients effectively. Our expertise in business catalyst hosting sets us apart as a top Adobe Business Catalyst expert.
        </p>
    </div>
    <div class="abs"><p>This final paragraph appears on top consciously...<p></div>
</div>
The proof is evident in the footer!

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

Tips for vertically aligning <p> and <div> elements without using the table-cell property

I am trying to align my text vertically in the middle using a ch-grid <div> (the circle color element). Is it possible to achieve this without specifying a display attribute for the <p> element? I plan to hide it by setting display:none initia ...

Experiencing issues with connecting to jQuery in an external JavaScript file

My jQuery formatting in the HTML file looks like this: <!doctype html> <html lang="en"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" type="text/javascript"></script> </head> < ...

Updating and managing the CSS style for button states

In my asp.net application, I have 5 list items functioning as tabs on a Masterpage. When a user clicks on a tab, I want to redirect them to the corresponding page and visually indicate which tab is active by changing its class. What is the most effective ...

CSS exhibiting variations on similar pages

Although the pages look identical, they are actually pulled from the same template file in Drupal but have different URLs. nyc.thedelimagazine.com/snacks In my document head, I've included a style rule that overrides a stylesheet further up the casc ...

Adding a 'dot' to the progress bar in Bootstrap enhances its visual appeal

I am currently working on a progress bar and I would like it to look similar to this: https://i.sstatic.net/TSDEy.png However, my current output looks like this: https://i.sstatic.net/rQhYc.png I'm puzzled as to why the tooltip is floating there, ...

Creating adaptable breakpoints for content using Bootstrap or pure CSS

I'm trying to create a responsive layout using the Bootstrap "row" and "col" classes, but I'm having trouble figuring out how to structure the content. Here's what I mean: https://i.sstatic.net/WkMmE.png This is my current HTML structure: ...

Is there a way to maintain the vertical alignment of spans within an HTML div after numerous drag and drop operations have taken place?

Recently, I created a JavaScript program (code provided below) to enable the dragging and dropping of <span> elements containing Greek characters within a basic <div> container. Upon initial page load, everything appears perfectly aligned vert ...

How can we create a touch and mouse-friendly horizontal scrolling navigation pattern?

I am trying to implement horizontal scrolling for video testimonials in a single row on a responsive website, but I am encountering an issue. The width of the container class is larger than col-12, which leaves space and causes horizontal scroll on the pag ...

Issue with plotted point labels failing to display correctly on X Range Chart for the initial date of each month - Highcharts

Currently, I am implementing a chart that displays the timeline of activities using an x range. However, I have encountered an issue with the popup displaying data information when hovering over the bars. The problem arises specifically on the first date ...

Incorporate props within the CSS template string of Emotion for enhanced styling flexibility

I am currently in the process of transitioning my design system from styled-components to emotion. Within styled-components, the following syntax is considered valid: export interface AvatarProps { // ... shape: AvatarShape; size: AvatarSize; } con ...

Utilizing CSS3 webkit-transitions with multiple properties on a div element along with multiple webkit-transition-delays

Is there a way to make a div slide 200px to the right and then reduce its scale by half separately? I want it to slide first and then scale, but currently both transformations happen simultaneously. I tried using webkit-transition-delay to set different ...

Employing jQuery Mobile Cache Manifest with PHP

Exploring the use of jquery mobile cache manifest, I'm curious to know if it's compatible with Php files as well. Appreciate any insights. ...

Neglecting images on Zoom

Looking to scale up the elements on an HTML page by 50%, without affecting the resolution of images. Despite trying zoom: 150% in CSS3, it ends up zooming pictures as well, resulting in blurry visuals. Is there a way to enlarge all HTML components while ...

Node.js is experiencing difficulties loading the localhost webpage without displaying any error messages

I am having trouble getting my localhost node.js server to load in any browser. There are no errors, just a buffering symbol on the screen. The code works fine in VS Code. Here is what I have: server.js code: const http = require("http"); const ...

Tips for preventing a bootstrap card image from overflowing in the card-body

I'm currently working with bootstrap cards and I've been able to prevent the card image from overflowing outside of the card area. However, I'm facing an issue where the bottom of the image overflows into the card-body region. I'm not s ...

Adding an Icon to a Tab in Ant Design - A Step-by-Step Guide

Is there a way to include an icon before the title of each open tab? I am currently using the antd library for tab creation, which doesn't provide a direct option for adding icons. Here is my code snippet along with a link to the jsfiddle https://jsfi ...

What steps are involved in setting up a dropdown side navbar?

Is there a way to automatically activate the next dropdown in the side navbar when I click on the 'Next' button? And similarly, can we open the previous dropdown in the side navbar when clicking the 'Previous' button? ...

Tips for clearing a text box on an AngularJS page when clicking a link within the page

On my HTML page, I have a search box and various category links. When a user enters text in the search box, I want to display: p in Products | filter {searchedText} If a user clicks on a category link, I want to display: p in Products | filter {categor ...

The svh/lvh units are experiencing unexpected issues when using Chrome on an iPhone

I'm facing an issue with my hero section that is supposed to take up the full height of the viewport. I recently tried using the new svh/lvh units, which seemed to work fine on desktop and Safari for mobile. However, when testing on Chrome for mobile ...

Expand Bootstrap navbar search box outside collapse menu

Currently, I am working on designing a navigation bar that showcases my brand on the left side, a full-width search bar in the center, and additional pages on the right. I am facing challenges in maintaining the full-width of the search bar without causing ...