我的 DOM 中有一个嵌套列表。所以我正在计算高度,基于我需要从列表底部向左浮动元素的高度。但目前它采用从顶部开始的默认 float left 属性。
Expected Output:
Antelope Camel
Bison Gazelle
Current Output:
Antelope Bison
Camel Gazelle
请帮帮我,它应该也支持 Internet Explorer,否则我可以使用 column-count
css 属性。
这是尝试过的:
JS:
var checkHeight = $(".checkHeight").height();
console.log(checkHeight);
if(checkHeight>233){
$(".checkHeight li.test").css("float","left");
}
最佳答案
我想我明白了。当父容器有足够的高度时,您希望它停止堆叠吗?我实际上认为这更多地与宽度有关。
var checkHeight = $(".checkHeight").height();
console.log(checkHeight);
if(checkHeight>233){
$(".checkHeight li.test").css("{'float' : 'left',
'width' : '100px}");
}
您还必须为父元素设置高度。也许 CSS 中的媒体查询是更好的途径,具体取决于您在做什么。
抱歉,如果我没有理解你在做什么,但没有 fiddle 或笔,很难看到你想做什么。
关于javascript - 如何根据高度 float 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32586826/