【发布时间】:2015-01-08 08:42:50
【问题描述】:
我正在尝试使用此处描述的技术创建一个 3 列布局,其中所有 3 列具有相同的高度(高度事先未知,因此我无法为高度指定硬编码值):
http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks
我正在稍微改变方法,因为我想使用“display: inline-block”而不是“float: left”。我使用的代码如下。
我遇到的问题是内联块似乎无法正常工作,因为它将我的 3 个 div 中的每一个都放在另一个之下,而不是并排放置。谁能向我解释为什么这不起作用?
这是我的 CSS:
#col1 {
width:33.33333333%;
vertical-align: top;
margin-left: 66.66666667%;
display: inline-block;
}
#col2 {
width:33.33333333%;
vertical-align: top;
margin-left: 100%;
display: inline-block;
}
#col3 {
width:33.33333333%;
vertical-align: top;
margin-left: 133.33333333%;
display: inline-block;
}
#container3 {
width: 100%;
margin-left: 0%;
background-color: green;
overflow:hidden;
}
#container2 {
width: 100%;
margin-left: -33.33333333%;
background-color: yellow;
}
#container1 {
width: 100%;
margin-left: -33.33333333%;
background-color: red;
}
这是我的实际 HTML:
<!doctype html>
<html>
<head>
<title>My Sample Columns</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="container3">
<div id="container2">
<div id="container1">
<div id="col1">
one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one one
</div>
<div id="col2">
two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two two
</div>
<div id="col3">
three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three three
</div>
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
宽度 33% 不适用于所有浏览器。它必须略低于 33%。少多少取决于浏览器如何计算宽度。如果没有边距,通常 32% 会起作用。
标签: css