我有一个简单的 php 页面,主要内容放在居中的表格中。我想放置一个从右上角开始的菜单。代码是这样的:
echo "<table class=\"center\">";
while($row= mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>";
... content...
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table class=\"topRightTable\">";
while($row= mysql_fetch_array($query2))
{
echo "<tr>";
echo "<td>";
... content ...
echo "</td>";
echo "</tr>";
}
echo "</table>";
使用这个 CSS:
table.center
{
margin-left: auto;
margin-right: auto;
text-align: left;
}
table.topRightTable
{
position:absolute;
top:50;
right:50;
}
body
{
min-width: 600;
}
这工作正常,直到窗口调整大小。然后右侧菜单将随窗口一起 float ,定位在其他元素之上。如何避免菜单项随窗口移动?
我曾尝试将页面的最小宽度设置为 600,并希望这会阻止右侧菜单进一步移动,但没有成功。
问题是:如何防止right-menu-table和center-table发生碰撞
最佳答案
另一个答案是正确的。假设你表的父级是正文:
body, html{
margin:0px;
padding:0px;
width:100%;
min-width:600px;
}
table.center {
margin-left: auto;
margin-right: auto;
text-align: left;
}
table.topRightTable{
float:right;
}
如果<body>
不是父级,将其更改为 .parent{ min-width:600px;}
关于php - 调整窗口大小时如何防止HTML元素移动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4009538/