WordPress博客上的简单浮动问题
我正在完全修改一个WordPress主题,并且遇到了一个非常简单的问题。请看我的页面: wordpress blog 当你向下滚动时,你可以看到一个空白区域在第一个帖子下。由于某种原因,该块没有向左浮动。每篇文章都有以下适合 645px 容器的 css:
.home-post-wrap { width: 285px; margin:0; float: left; background-color: #FFF; padding: 15px; overflow: hidden; border-bottom:1px dotted #C5C5C5; border-right:1px dotted #C5C5C5; }
关于如何使页面在这里正确流动的任何想法吗?
I am modifying a wordpress theme completely, and have run into one very simple problem. Please look at my page here: wordpress blog When you scroll down, you can see the one blank area under the first post. For some reason, that block isn't floating left. Each post has the following css that fits in a 645px container:
.home-post-wrap { width: 285px; margin:0; float: left; background-color: #FFF; padding: 15px; overflow: hidden; border-bottom:1px dotted #C5C5C5; border-right:1px dotted #C5C5C5; }
Any idea on how to make the page flow correctly here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
crimson_penguin 是正确的。这是因为柱子的高度不同。每两列你不想做一次清除。这里最简单的事情是查看循环的索引,并在每 2 次之后回显一个clearfix。您可以使用模数来执行此操作,和/或将类应用于
1、3、5 等处的类。 ..
到clear:left
。这是我用来清除的 PHP 函数。
基本上,您向其传递三个参数(第二个和第三个是可选的),其中第一个是
$count
或要查看的对象(例如for
循环)和$odd / $even
是在循环中遇到奇数或偶数项时使用的字符串。这是实际操作:
我正在
$key
上执行循环,在本例中恰好是0, 1,... n
。结果如下:只需对奇数应用一些
clear:left
,就可以了!crimson_penguin is correct. It's because the columns are different heights. Every 2 columns you wan't to do a clear. The easiest thing to do here would look at the index of the loop and echo a clearfix after every 2. You can do this with modulo, and/or apply a class to the ones at
1, 3, 5, etc...
toclear:left
.Here is a PHP function of mine that I use to clear.
Basically, you pass it three arguments (the second and third are optional) where the first is the
$count
, or the object to look at (for example$i
in afor
loop) and$odd / $even
are strings to be used when an odd or even item in the loop is encountered.Here it is in action:
I'm doing the cycle on the
$key
which in this case happens to be0, 1,... n
. The result is the following:Simply apply some
clear:left
to the odd ones, and you'll be all set!它向左浮动,问题是第一个块比第二个块高,使其在下方突出,因此第三个块仍然与前两个块在同一条“线上”,就像您期望的那样如果第一个块的高度是原来的两倍。
您可能想要的是
每 2 个区块之间...但这在 WordPress 中可能很难做到。另一个潜在的解决方案是对它们设置 min-height,但这不会那么好(并且在 IE6 中不起作用)。
It is floating to the left, the problem is that the first block is taller than the second, making it stick out below, and so the third block is still on the same "line" as the first two, like you would expect it to if the first block was twice as high.
What you probably want, is a <div style="clear: left;"></div> between every 2 blocks... but that might be hard to do in WordPress. Another potential solution would be min-height on them, but that wouldn't be quite as nice (and wouldn't work in IE6).