具有相同高度的响应列的问题

时间:2013-05-16 16:16:40

标签: jquery html css height equals

这是我的辩论,问题已经解决,但我无法弄清楚为什么css-tricks.com上使用的方法不起作用。我认为它没有用的唯一原因是因为我的列是响应性的。

这是问题的jsfiddle

解决方案1 ​​Nicolas Gallagher方法

不工作,为什么。因为我的客户可以随时添加另一个框(告诉我添加另一个框,或减去一个框)。所以我需要我的代码才能做出响应。我顺便把css拿走了,但是如果你能看一下并告诉我如何使这个工作,那就太好了。我坚持的部分是选择UL的孩子。

.pseudo-three-col .col:nth-child(1) { left: 33%; }
.pseudo-three-col .col:nth-child(2) { left: -33.3%; }
.pseudo-three-col .col:nth-child(3) { left: 0; }

解决方案2 jQuery解决方案

Jsfiddle

我的jQuery捕获无序列表的高度并将其应用于我的列表项高度。完美的工作。但我是一个真正的CSS开发人员,不想jQuery代码不需要的东西。时间限制导致了这种解决方案。

    $(".basic:last-child").show();
       // Optimalisation: Store the references outside the event handler:
    var catheight = $('ul.categories').height();

    $('ul.categories li.clearfix').css({"height" : "" + catheight + ""});

2 个答案:

答案 0 :(得分:3)

这似乎有效:http://jsfiddle.net/David_Knowles/LQ54K/ 也许你可以分享一下你不理解的那一点?

.top_category {
    position: relative; background:none orange; z-index: -1;
}
.top_category:before, .top_category:after,
.categories:before, .categories:after {
   content: " ";
   position: absolute;
   z-index: -1;
   top: 0;
   left: 20%;
   width: 20%;
   height: 100%;
   background: #ccc;
}
.top_category:before {
   left: 0%;
   background: #eee;
}
.top_category:after {
   left: 20%;
   background: green;
}
.categories:before {
   left: 40%;
   background: pink;
}
.categories:after {
   left: 60%;
   background: yellow;
}

在你的小提琴中,上面的代码丢失了吗?这实际上使得虚拟列效果起作用。只是为了清楚;这些不是您放置内容的列,并且实际内容列的高度不相等。只有位于内容后面的Pseudo列才相等。这可能是混乱吗?

答案 1 :(得分:0)

此外:

此示例包含带边框的列以及它们之间的间隙:http://jsfiddle.net/David_Knowles/Vz5pT/

这是应用列之间的伪差距的xtra代码

.categories li:after {
    background: none #FFFFFF;
    border-color: #555555;
    border-style: solid;
    border-width: 0 1px;
    bottom:0;
    content: "";
    display: block;
    left: 20%;
    margin: 0 0 0 -2px;
    position: absolute;
    top: 0;
    width: 4px;
    z-index: 1;
}
.categories li:nth-child(2):after {left: 40%;}
.categories li:nth-child(3):after {left: 60%;}
.categories li:nth-child(4):after {left: 80%;}

如果有些内容不明确,请告诉我。

相关问题