Absolute positioning and hiding overflow
P粉451614834
P粉451614834 2023-08-21 19:30:21
0
2
381
<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粉451614834
P粉451614834

reply all(2)
P粉715304239

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.

P粉792026467

Set the outer <div> to position: relative and the inner <div> to position: 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!