如何解决 IE CSS 百分比舍入问题?

发布于 2024-07-26 02:27:56 字数 480 浏览 1 评论 0原文

我正在尝试创建一个动态网站,其中三个浮动框彼此相邻。 它们的宽度各为 33.33%。 它们周围的容器 div 的宽度为 75%。

我在这里找到了一篇关于该问题的文章: CSS:跳列
我还在这里找到了相同问题的示例: 跳栏示例

拖动窗口大小即可在 IE7 或更早版本中查看跳转情况。

有人知道是否可以解决这个问题吗? (没有 JavaScript)

I'm trying to create a dynamic site where I have three floating boxes next to eachother. They are 33.33% in width each. The container div around them is 75% in width.

I've found an article about the problem here: CSS: Jumping columns
I've also found an example of the same problem here: Jumping columns example

Drag the window size to see the jumping in IE7 or earlier.

Anyone knows if it's possible to get around this? (without Javascript)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

蝶舞 2024-08-02 02:27:56

我根据情况使用两种不同的解决方案。 首先,尝试 Nicole Sullivan 方法(在行中的最后一个元素上使用 overflow:hidden; 而不是 float/width):

http://www.stubbornella.org/content/2009/07/23/overflow-a-secret-benefit/< /a>

.container {
  width: 75%;
}

.box1 {
  width: 33.33%;
  float: left;
  display: inline; /* fixes another IE bug */
}

.box2 {
  overflow: hidden;
}

这在大多数情况下都有效。

如果做不到这一点,我会向最后一个元素添加几个像素的负边距。

.box2 {
  width: 33.33%;
  float: left;
  display: inline; /* fixes another IE bug */
  margin-right: -3px;
}

如果最后一个元素向右浮动,只需在左侧添加负边距即可。 到目前为止,这在少数不适合溢出的情况下对我有用。

I use two different solutions depending on the situation. First, try the Nicole Sullivan approach (using overflow: hidden; on the final element in a row instead of float/width):

http://www.stubbornella.org/content/2009/07/23/overflow-a-secret-benefit/

.container {
  width: 75%;
}

.box1 {
  width: 33.33%;
  float: left;
  display: inline; /* fixes another IE bug */
}

.box2 {
  overflow: hidden;
}

This works in most cases.

Failing that, I add a negative margin of several pixels to the last element instead.

.box2 {
  width: 33.33%;
  float: left;
  display: inline; /* fixes another IE bug */
  margin-right: -3px;
}

If that last element is floated right instead, just add the negative margin to the left. So far that has worked for me in the few cases where overflow didn't fit.

两人的回忆 2024-08-02 02:27:56

在这种情况下,我倾向于使用仅适用于 IE 的样式表来解决问题,该样式表会捏造值直到它们起作用。 在本例中,只需将宽度设置为 33%,这并不完美,但这就是网络的本质。

In a situation like this, I would tend to get round the problem using an IE-only stylesheet that fudges the values until they work. In this case, just set the widths to 33%, it won't be perfect but then that's just the nature of the web.

橘虞初梦 2024-08-02 02:27:56

我认为一个简单的答案可能是根本不舍入,只需创建一个宽度为 1% 的最终“间隔”元素,该元素共享 1/3 元素的外观。 即使 IE 也应该能够处理 33 + 33 + 33 + 1 舍入。

I think that a simple answer might be to not round at all, just create a final "spacer" element with a 1% width that shares the look of the 1/3rd elements. Even IE should be able to deal with a 33 + 33 + 33 + 1 rounding.

浪菊怪哟 2024-08-02 02:27:56

我有同样的问题。 ie7 没有正确渲染 33.33%。 33% 的人会这么做,但结果却相差甚远。 我使用了上面第一个响应中第二个代码块的建议,再加上一点 ie hack。 它对我有用,我希望它有帮助。

.all-boxes {
   width: 33.33%;
   float: left;
   display: inline;
   *margin-right: -1px; /* Add the asterisk */
 }

边距值可能需要根据您的实现进行更改,但 1px 对我有用。

I had the same problem. ie7 did not render 33.33% correctly. It would work with 33% but then it was a hairline off. I used the advice from the second block of code in the first response above, plus a little ie hack. It worked for me, I hope it helps.

.all-boxes {
   width: 33.33%;
   float: left;
   display: inline;
   *margin-right: -1px; /* Add the asterisk */
 }

The margin value might need to change based on your implementation, but 1px worked for me.

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