【发布时间】:2016-04-16 09:42:41
【问题描述】:
当我在 HTML 中使用 CSS 表格和绝对位置位于表格顶部的黑色图层时,我有一个奇怪的行为。
当层被启用时,(display: block),那么它就会破坏布局。但是当我禁用 is (display: none) 时,一切都很好。
这是一个小例子(您必须通过开发人员工具更改 css)。有什么我忘记设置的吗?
不能用 flexbox 代替表格!
html,
body {
width: 100%;
height: 100%;
}
body {
display: table;
table-layout: fixed;
}
#menu {
display: none;
background: #28292D;
width: 200px;
position: fixed;
left: -300px;
top: 0;
height: 100%;
text-align: center;
padding-left: 15px;
padding-right: 15px;
z-index: 3;
}
#blackLayer {
background: rgba(0, 0, 0, 0.5) none repeat scroll 0 0;
display: none;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: 2;
height: 1265px;
display: block;
}
#sidebar {
display: table-cell;
vertical-align: top;
width: 223px;
background: #3d464d none repeat scroll 0 0;
}
#content {
display: table-cell;
vertical-align: top;
background: #f0f0f0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="menu"></div>
<div id="blackLayer"></div>
<div id="sidebar"></div>
<div id="content"></div>
</body>
</html>
【问题讨论】:
-
一个表是一个显示值,如果你改成block就破坏了这个表。
-
这不是我写的。我不会将表格更改为阻止。我将图层更改为块/无,并且图层具有绝对位置。
-
图层位于显示表格元素内,即您的身体。至少不是一个好的做法,并且表格布局被破坏了,因为如果您更改所有标记,您将获得正确的行为而无需奇怪的编码
标签: html css css-position css-tables