Home > Web Front-end > CSS Tutorial > Why Doesn\'t Overflow:hidden Work on Absolutely Positioned Nested DIVs Unless the Parent is Positioned Relatively?

Why Doesn\'t Overflow:hidden Work on Absolutely Positioned Nested DIVs Unless the Parent is Positioned Relatively?

Patricia Arquette
Release: 2024-12-02 15:23:12
Original
527 people have browsed it

Why Doesn't Overflow:hidden Work on Absolutely Positioned Nested DIVs Unless the Parent is Positioned Relatively?

Absolute Positioning and Overflow Hidden Conundrum

When dealing with nested DIVs, it can be challenging to enforce overflow hidden properties on the outer DIV if it's not positioned absolutely. This can lead to the inner DIV, which is positioned absolutely, disregarding the overflow hidden behavior.

Consider the following HTML structure:

<div>
Copy after login

Where #first has an overflow hidden property and #second is positioned absolutely. In this scenario, #second will not respect the overflow hidden constraint.

To resolve this issue without setting #first to position absolute, consider the following solution:

  1. Position #first as relative:

    #first {
      position: relative;
    }
    Copy after login
  2. Keep #second positioned absolutely:

    #second {
      position: absolute;
    }
    Copy after login

With this configuration, #second will now adhere to the overflow hidden property of #first. This allows you to maintain the desired layout while ensuring the inner DIV respects the overflow constraints.

The above is the detailed content of Why Doesn\'t Overflow:hidden Work on Absolutely Positioned Nested DIVs Unless the Parent is Positioned Relatively?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template