显示:IE7 的表格?

发布于 2024-09-29 11:40:50 字数 493 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2024-10-06 11:40:51

如果您在父 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 have display:table-row; and display: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; or display:inline-block; (but the last will make problems in IE, too) - and remove that senseless display:table; on the parent-div

夏夜暖风 2024-10-06 11:40:50

嗯,为什么你的最左边的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文