Home >Web Front-end >HTML Tutorial >How to solve the problem of container 1 covering container 2? _html/css_WEB-ITnose
Container 1 covers container 2, please help!
<table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <div id="div-datagrid" style="z-index: 0; width: 100%; position: absolute; height: 459px; left: 0px; top: 0px; background-color: Yellow;"> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> </div> </td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> 容器2 </td> </tr> </table> </td> </tr> </table>
This has nothing to do with the container. It is because your div has the position attribute set, so the div will be separated from the document. Flow
The positions of the two tables above have not changed, but the div is covered by the displayed position
<table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td>sadfas <div id="div-datagrid" style="z-index: 0; width: 100%; position: absolute; height: 459px; left: 110px; top: 110px; background-color: Yellow;"> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> </div> </td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> 容器2 </td> </tr> </table> </td> </tr> </table>
<table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td>sadfas <div id="div-datagrid" style="z-index: 0; width: 100%; position: absolute; height: 459px; left: 110px; top: 110px; background-color: Yellow;"> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> </div> </td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> 容器2 </td> </tr> </table> </td> </tr> </table>
Uh-huh. . . If you set the table with id="div-datagrid" to absolute positioning, the absolutely positioned element will be separated from the original document flow, so the subsequent table will think that there is no table in front of it and will be displayed directly from the upper left corner. So the absolute table covers the second table.
You can take a look at W3CSchool’s instructions on absolute positioning http://www.w3school.com.cn/css/css_positioning_absolute.asp
This must be something you practice writing by yourself. If the first The table insists on being absolute; then you can set the z-index in the style of the first table to -1, and the tables that are covered later will be displayed, but talble1 and talbe2 overlap
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head></head><body><table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> <div id="div-datagrid" style=" width: 100%; height: 459px; left: 0px; top: 0px; background-color: Yellow;"> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> <p> 容器1</p> </div> </td> </tr> </table> <table width="100%" cellpadding="0" cellspacing="0" border="1"> <tr> <td> 容器2 </td> </tr> </table> </td> </tr> </table></body></html>
I want to implement the freezing function of columns. I cannot remove z-index: 0; position: absolute;
Is there a better way to prevent the two tables from overlapping?
<td style="position: relative;left: 0px; top: 0px;height:459px;">