How can I transfer the height of a parent div to a child div with absolute positioning?

I'm facing an issue where the child div (.timeline) needs to adjust its height as the parent divs (.tea-history) height increases. However, using height:inherit; didn't work as expected because the child div inherited an auto height from the parent div. When I attempted to use height:100%; it ended up taking the height of the entire page.

Does anyone have a solution for making the .timeline class increase its height along with the parent div?

.tea-history {
  display: flex;
  flex-direction: column;
  margin-left: auto;
  margin-right: auto;
  margin-top: 50px;
  margin-bottom: 20px;
  height: 800px; /*Currently i have set the height to 800 so the timeline is visible*/
  width: 90%;
  margin-top: 70px;
}

.tea-history .timeline {
  position: absolute;
  height: inherit;
  width: 3px;
  border-radius: 20px;
  background-color: #7aaa62;
  margin-top: 50px;
  margin-left: 50px;
}

.tea-history .frame {
  width: 80%;
  display: grid;
  grid-template-columns: 20px auto;
  gap: 33px;
  margin-top: 30px;
  margin-left: 42px;
}

.tea-history .frame .timeline-dot {
  display: flex;
  align-items: center;
}

.tea-history .timeline-dot .outer-dot {
  position: absolute;
  height: 15px;
  width: 15px;
  border-radius: 50%;
  border: #000 solid 3px;
}

.tea-history .timeline-dot .inner-dot {
  position: absolute;
  height: 10px;
  width: 10px;
  border-radius: 50%;
  background-color: #000000;
  margin-top: 2px;
  margin-left: 2px;
}
<div class="tea-history">
  <h3 class="heading">History</h3>
  <div class="timeline"></div>
  <div class="frame">
    <div class="timeline-dot"><span class="outer-dot"><span class="inner-dot"></span></span>
    </div>
    <div class="content">
      <h4>2035 - 2054</h4>
      <p>
        ...
      </p>
    </div>
  </div>
</div>

Answer №1

Since absolutely positioned elements are taken out of the flow and not considered by other elements, setting a parent's height based on an absolutely positioned element is not possible, which is why using `inherit` did not work.

To resolve this issue, you have two options: either use fixed heights or incorporate JavaScript.

Here's a clever workaround:

Replicate the content of .tea-history and .timeline within relative divs that are hidden with display:none in the parent div. Create duplicates named .tea-history_duplicate and .timeline_duplicate, placing .timeline_duplicate above and .tea-history_duplicate below.

When your jQuery script targets the absolute div, adjust it to align with the relative div (.timeline_duplicate or .tea-history_duplicate) by setting it to display:block; and visibility:hidden;. The relative child will remain invisible but extend the height of the parent 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

Contrasting the distinctions between a pair of CSS class declarations

After using my customized CSS class named myclass alongside Bootstrap's built-in class container, I have a question about how to declare a div element with both classes. Should I go with: <div class="myclass container">some code</div> o ...

Arranging elements within the container: navigation bar, slideshow, and introductory section

I currently have a setup with a navbar, carousel, and intro section. Desired Layout: Carousel should be full width and height Navbar positioned on top of the carousel Intro content placed below the carousel Current Issues: The images in the carousel ...

After exiting the PWA, the IOS camera displays a black screen

I have implemented an HTML file input to open the camera and capture photos for my Progressive Web App (PWA). <input type="file" accept="image/*" capture="camera" name="photo" id="photo-input-js" data-project-id="<?php echo $projectId ?>"> // ...

What is the best method for inserting a specific value into a tuple that exists within another tuple within Python using Django?

My dictionary for Categories consists of tuples within a tuple, but I am looking to extract only the literals - the category names. from django.db import models CATEGORIES = ( ('a', 'Clothing'), ('b&ap ...

Interactive search tool for toggling visibility of elements

Hello everyone, this is my initial post on StackOverflow. Keeping my fingers crossed that it goes smoothly! <input type="Text" id="filterTextBox" placeholder="Filter by name"/> <script type="text/javascript" src="/resources/events.js"></scr ...

Encountering issues with the setSinkId() function in an Electron application

I'm currently working on an app that involves playing audio and allowing users to switch between audio devices. My main issue arises when attempting to utilize the setSinkId() function - it consistently results in a DOMException AbortError with the er ...

Is it possible to showcase D3 charts on an .epub file?

For my research project, I am exploring the possibilities of .epub files and experimenting with embedding JavaScript code to display data visualizations. I am currently using calibre to convert an HTML file containing D3 scatterplots into an .epub. The s ...

Developing Multiple Views in Django

I am completely new to using Django and I am facing a challenge in creating multiple views with corresponding buttons on the main page. I managed to create different views for various filters of the table, but now I am stuck trying to figure out how to set ...

Customize the appearance of the placeholder text in ui-select-match

I am trying to style the placeholder text of the following element: <ui-select-match placeholder="My hint"> {{$someItem}} </ui-select-match> I want to change the style of the placeholder text to be bold, italic, or other formatting option ...

Ways to confirm the validation of radio buttons in a form and implement CSS

I am having trouble adding validation to a form with radio buttons displayed as labels. I want to show a red border around the radios/labels or outer div when a radio button hasn't been checked before the user submits the form. I have attempted this ...

AngularJS: How can I eliminate the #! from a URL?

Looking for guidance on how to remove #! from the URL in AngularJS using ng-route. Can anyone provide a step-by-step process on removing #!? Below is the code snippet: index.html <head> <script src="https://ajax.googleapis.com/ajax/libs/ang ...

Displaying all divs when the checkboxes are unchecked

My code displays a product list with various details stored in different divs based on data attributes like brand, store, and more. A friend helped me develop a filter using checkboxes for record selection. However, I need to make a small modification to i ...

Is there a way to soften the repetitive elements in the background image?

Is there a method to blur the part of a background image that is repeated, such that if it is positioned in the center, the sides of the image appear blurry as well? ...

Searching for a comprehensive guide to web-related terminology that is widely accepted

Constantly immersing myself in studying the languages I am familiar with and exploring new development concepts and languages is a regular practice for me. When it comes to books, O'Reilly is my go-to choice, but when it comes to online resources, I&a ...

Ways to implement CSS on a parent element by manipulating its child element

Hello, I am looking to apply CSS to a parent element based on its child. <li> <div> <label> <b style="display: none;">Name and Date of Event*: </b> </label> </div> </li> ...

Undesirable gap found within the bootstrap columns

I'm experiencing issues with the design of my form controls in Bootstrap. I have divided the screen into three columns, with each column being 4 md wide. The General Agreement control is defined as col-md-8 to span across. I'm unsure why there is ...

Avoid having the java applet destroyed when the container is hidden

I am working with multiple DIVs, each containing text, a java applet (unfortunately...) and buttons. I am currently creating a search function to dynamically show and hide these DIVs. However, whenever I use display:none on a DIV, the applet inside it se ...

Find the nearest class name in proximity

I am attempting to find the closest anchor element with a class that has been clicked. However, not all links will have a class assigned to them, so I need to consider the parent class as well. Since the class names will vary, hardcoding specific class nam ...

Angular: Design dependent on attributes

Can I customize the styling of a div in accordance with a boolean property called "isActive" on my controller using Angular? <div class="col-md-3" (click)="isActive = !isActive"> <div class="center"> <i class="fa fa-calendar"& ...

Transferring information between two independent React applications

I am facing a challenge with an HTML page that is incorporating two separate webpack-generated React bundles. Each bundle has its own index.js entry file, which simply executes a RenderDOM.render() of its corresponding component to its designated <div&g ...