显示:IE7 的表格?
我在 CSS 中有几列,使用 float:left 属性来水平对齐它们。但由于它漂浮在左侧,我无法将所有 div 居中。
所以我发现,如果我用另一个带有 display:table 属性的 div 包裹我的列,一切都会完美......但在 IE7 中不行(idd,不支持此属性 -.-)。
有人有这方面的技巧吗?
这是我的代码:
<div style="display:table">
<div style="float:left">A column</div>
<div style="float:left">A column</div>
<div style="float:left">A column</div>
<div style="float:left">A column</div>
</div>
I've a several columns in CSS, with float:left property to align them horizontally. But as it float in the left side, I can't center all the divs.
So I found that if I wrap my columns with another div with display:table property, all works perfectly... but not in IE7 (idd, this property is not supported -.-).
Does anybody has a hack or trick for this?
Here is my code:
<div style="display:table">
<div style="float:left">A column</div>
<div style="float:left">A column</div>
<div style="float:left">A column</div>
<div style="float:left">A column</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在父 dic 上使用
display:table;
,则应该有display:table-row;
和display:table-column;
-其中的元素 - 在这种情况下浮动没有任何意义。请查看此或向 Google 询问更多信息。(如果你想显示一个表格,为什么不使用
table
元素?在使用表格进行布局的情况下,这是一个不好的做法,但是通过以下方式执行相同的 sh***用 table-crap 代替 divitis 并不会让它变得更好)编辑:如果你只是想要并排并居中显示你的div,你可以简单地尝试使用
display:inline;
或display:inline-block;
(但最后一个会出现问题IE 也是如此) - 并删除父 div 上无意义的display:table;
if you use
display:table;
on the parent dic, you should havedisplay:table-row;
anddisplay:table-column;
-elements in it - and floating doesn't make any sense in that case. please take a look at this or ask google for more information.(if you want to display a table, why don't you use the
table
-element? In cases where tables are used for layout, thats a bad practice, but doing the same sh*** by substituting table-crap for divitis doesn't make it better)EDIT: if you just want to display your divs side by side and centered, you could simply try to use
display:inline;
ordisplay:inline-block;
(but the last will make problems in IE, too) - and remove that senselessdisplay:table;
on the parent-div嗯,为什么你的最左边的 div 上有一个 float: left ?我认为这会带来一些麻烦。你有CSS吗?您应该在外部 div 上设置 margin-left: auto 和 margin-right: auto 。看看此页面,里面有所有详细信息。似乎您可能还必须添加 br 标签或类似标签
Hm, why are you having a float: left on your leftmost div? I think that will cause some trouble. Do you have any css? You should have margin-left: auto and margin-right: auto on your outer div. Take a look on this page, there's all the details. Seems like you might have to add br-tags or similar too