Absolute positioning and hiding overflow
P粉451614834
P粉451614834 2023-08-21 19:30:21
0
2
332

We have two DIVs, one nested inside the other. If the outer DIV is not set to be absolutely positioned, then the absolutely positioned inner DIV will not respect the overflow hiding of the outer DIV.


#first { width: 200px; height: 200px; background-color: green; overflow: hidden; } #second { width: 50px; height: 50px; background-color: red; position: absolute; left: 250px; top: 250px; }


Is there a way to make the inner DIV follow the overflow hiding of the outer DIV without setting the outer DIV to be absolutely positioned (as this would break our overall layout)? Also, relative positioning is not an option for our inner DIV since we need to "highlight" a table TD.


#first { width: 200px; height: 200px; background-color: green; } #second { width: 50px; height: 400px; background-color: red; position: relative; left: 0px; top: 0px; }


Are there any other options?

P粉451614834
P粉451614834

reply all (2)
P粉715304239

What about usingposition: relativefor external divs? In the example of hiding the inner div. Since top or left are not specified, it will not move within the layout.

    P粉792026467

    Set the outer

    toposition: relativeand the inner
    toposition: absolute. This should work for you.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!