The combination of absolute positioning and percentage-based height measurements allows for

For more information, go to http://jsfiddle.net/A2Qnx/1/

<div id='w'>
   <div id='p'>
      <div id='c'>
      </div>
   </div>
</div>

With absolute positioning enabled, div P has a height of 60px (50 from the parent + 10 from padding).

If you disable absolute positioning, both div P and div W will have a shared height of 110px (100 from the child elements + 10 from padding).

I am curious to know why this behavior occurs.

1) When absolute positioning is on, why does P's height derive from the min-height of the parent instead of the children's heights? And why is padding only applied to P?

2) When absolute positioning is off, why does P's height come from the children's heights instead of the min-height of the parent? And why is padding applied to both P AND W?

Answer №1

Padding is specifically applied to the #p element...

Regarding height, absolute positioning removes the element from the regular document flow. Setting the height to 100% causes the element to inherit the full height of any non-statically positioned parent (or the body if no other parent is found). Since it is outside the normal flow, the contents of the #w element are effectively empty, which is why it reverts back to its minimum height.

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

Choose certain table cells that do not have an identifier or any classes assigned to them

My table has 3 rows and 3 data cells. To select the first row, first data cell, and all bold tags from it: tr + td b {} To select the second row, second data cell, and all bold tags from it: tr+tr > td+td b {} I need help selecting them without usi ...

PHP encountered an issue while trying to compare the value stored in the $_POST variable with the value stored in a

In my current project, I have utilized a JSON file to store data and PHP to retrieve and display it. However, I am facing an issue when comparing values from $_POST - specifically, if the value contains spaces, the comparison fails. Here is the problematic ...

issue with varying levels of user authentication

I encountered an issue with the multi-level user login functionality in my PHP MySQL project. While I am able to login as an admin without any problems, nothing happens when attempting to log in with a different user. Is there something crucial that I migh ...

Responsive menu not functioning properly with jQuery

I am currently working on a website located at . My goal is to incorporate the navigation plugin called MeanMenu into the site. I have followed all the instructions provided in the tutorial: adding the jQuery script to my HTML, including the CSS in the hea ...

Random variable without repetition in SASS

I have a unique project where I am tasked with incorporating a list of 5 specific colors into 10 different div elements. The challenge is that each color must be used twice and in a completely random order without any repetition of colors. Although utilizi ...

Tips for dynamically adding an HTML element to index.html using JavaScript

How can I use JavaScript to insert cards into a container or display them in flex? Currently, the cards are not displaying as desired. I attempted to insert data into the note class using insertAdjacentHTML in JavaScript, but struggled to place them in the ...

Leveraging PHP to dynamically insert image file names into a directory for populating the HTML img src attribute in a Bootstrap

I am trying to dynamically populate a Bootstrap carousel with images from a folder by using PHP to scan the image files. However, instead of displaying the images in the carousel, only the names of the images are being listed. Below is my code, and I have ...

Padding for the initial element in a carousel display

I am currently working on implementing owl carousel with stage padding. My goal is to use the carousel with loop:false, and have the first item displayed without left padding, while maintaining consistent padding for both items on the left and right after ...

In the thymeleaf fragment, the th:field attribute is marked with a crimson underline

I am facing an issue with a fragment that opens a modal when a button is clicked. Inside the modal, there is a form with a text field for token and submit button. However, I am getting a red squiggle underneath the th:field attribute "token", and I'm ...

Selection menu drops down once the save is complete

I have two drop-down menus named source and campaign, displaying data from the database. In addition to these drop-downs, there are other input fields as well. My concern is that I want to save the filled data along with the selected options in the drop-do ...

Tips for customizing your MUI slider design

import * as React from "react"; import Box from "@mui/material/Box"; import Slider from "@mui/material/Slider"; function valuetext(value) { return `${value}°C`; } export default function RangeSlider() { const [value, se ...

Modifying webpage design using JavaScript for styling

Is there a way to change the css style(defined in the page source) dynamically with Java? I know it is possible to do it with JavaScript. If there isn't, are there other situations where JavaScript is the only choice developing a web app? ...

Avoid wrapping elements

Is there a foolproof method or best practice to prevent an HTMLElement from wrapping? Specifically, I'm referring to elements with relative positioning. One possible solution could be using absolute elements and adjusting their left position based on ...

Creating a full width and height slider with a header menu that is responsive to all device screen sizes

Looking to create a full-width slider with a header that adjusts for all screen sizes, especially larger devices. I've been searching online but haven't found a satisfactory solution yet. If anyone has any ideas or tips on how to achieve this, pl ...

IE6 is not displaying the tag styles correctly

My website has a section that shows two links next to each other. While it's displaying correctly on most browsers, it seems to have issues specifically in IE6. You can view the issue on this fiddle. Can anyone shed some light on why this is happenin ...

Angular: How to Disable Checkbox

Within my table, there is a column that consists solely of checkboxes as values. Using a for loop, I have populated all values into the table. What I have accomplished so far is that when a checkbox is enabled, a message saying "hey" appears. However, if m ...

Struggling to align the Title Tags perfectly in the center of Images

When attempting to center align images and their post titles, I encountered an issue where the left part of the image and title were being cut off by a small margin. Despite trying various methods, I was unable to successfully center the title tags. You ca ...

Unable to process form submission using Ajax in ASP.NET MVC

I'm having trouble with submitting a form using ajax and opening a modal dialog after the ajax function is successful. Whenever I click the submit button, the process doesn't complete. Where could the issue be, in the ajax method or somewhere el ...

Develop a unified help document that is compatible across multiple platforms using an existing markdown file

I have been tasked with working on an existing project that already has detailed functionality and relevant information in a markdown file. My goal is to create a universal help file that can be easily viewed on various platforms including Windows, macOS ...

At first, struggling to dynamically adjust the height of a collection view based on JSON data in a Swift project

Within a tableview cell, I am utilizing a collection view. When I return homeData?.result?.category_json?.count ?? 0 to populate the collection view with JSON data, the height of the collection view does not adjust dynamically at first. However, when I scr ...