首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS div换行和垂直空白

问CSS div换行和垂直空白
EN

Stack Overflow用户
提问于 2012-09-07 04:39:04
回答 3查看 366关注 0票数 0

当容器的宽度改变时,我尝试让几个div元素换到下一行。包装部分运行良好,当没有足够的宽度使其适合时,盒子将下降到下一行,但是如果高度不同,第一行元素和第二行元素之间会有间隙。在下面的示例中,我希望将框b4滑入b1下的空白区域。这个是可能的吗?谢谢你的帮助。

http://jsfiddle.net/86xcY/

EN

回答 3

Stack Overflow用户

发布于 2012-09-07 04:53:06

代码语言:javascript
复制
    hello one small changes  i this case you must set the min-height and  max-height     details as follows. and when you add the content the height automatically increased.


   #box3 {
    display: table-cell;
    max-height: 300px;
    min-height: 98px;
    width: 200px;
 }
票数 0
EN

Stack Overflow用户

发布于 2012-09-07 05:15:56

这可能就是你要找的东西。它可能会被优化很多,并调整以更好地满足您的需求。此外,当它转到单个列时,有一个bug,我不想费心对它进行排序。更有可能的是,最好的解决方案是在特定屏幕宽度下将所有margin-top值设置为0。

http://jsfiddle.net/86xcY/1/

代码语言:javascript
复制
$(window).resize(function(e){
    var wid = $("#container").width();

    $("#container .box").each(function(index, element){
        $(this).css("margin-top", 0);
        var top = $(this).position().top;
        var left = $(this).position().left;

        var upwards = null;
        var htm = $("html")[0];

        if (top > 0){
            var cTop = top;
            while ((upwards == null || upwards == htm) && cTop > 0){
                cTop -= 10;
                upwards = document.elementFromPoint(left, cTop);
            }
            var uTop = $(upwards).position().top;
            var uHei = $(upwards).height();

            var negMarg = (uTop + uHei) - top;

            if (negMarg < 0){
                $(this).css("margin-top", negMarg);
            }
            else if (negMarg > 0)
                $(this).css("margin-top", 0);
        }
    });
});​
票数 0
EN

Stack Overflow用户

发布于 2012-09-07 04:44:27

如果您将float:left添加到您的元素中,这是可能的。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12308018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档