search

Home  >  Q&A  >  body text

Absolute positioning and hiding overflow

<p>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. </p> <p><br /></p> <pre class="brush:css;toolbar:false;">#first { width: 200px; height: 200px; background-color: green; overflow: hidden; } #second { width: 50px; height: 50px; background-color: red; position: absolute; left: 250px; top: 250px; }</pre> <pre class="brush:html;toolbar:false;"><div id="first"> <div id="second"></div> <div id="third"></div> </div></pre> <p><br /></p> <p>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. </p> <p><br /></p> <pre class="brush:css;toolbar:false;">#first { width: 200px; height: 200px; background-color: green; } #second { width: 50px; height: 400px; background-color: red; position: relative; left: 0px; top: 0px; }</pre> <pre class="brush:html;toolbar:false;"><table id="first"> <tr> <td> <div id="second"></div> </td> </tr> </table></pre> <p><br /></p> <p>Are there any other options? </p>
P粉451614834P粉451614834495 days ago452

reply all(2)I'll reply

  • P粉715304239

    P粉7153042392023-08-22 12:40:56

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

    reply
    0
  • P粉792026467

    P粉7920264672023-08-22 00:26:59

    Set the outer <div> to position: relative and the inner <div> to position: absolute. This should work for you.

    reply
    0
  • Cancelreply