我正在尝试匹配以下网站上内容区域和侧边栏的高度:
我已将以下代码行添加到我的文件 js.js
$('.height-page').matchHeight();
这是我的内容区域的类:
<div id="content" class="grid_8 height-page">
还有我的侧边栏:
<aside id="sidebar" class="grid_4">
<div class="content height-page">
脚本似乎加载正常,只是它们的高度不匹配。我得到的所有这两个元素的输出都是沿着这些线:
<div class="grid_8 height-page" id="content" style="">
我最初确实以 Js 中的每个元素为目标,使用它们各自的 ID/类,但也无法让它工作。所以我想也许我只能将高度匹配应用于特定类,因此我使用 .height-page ,但当然这也不起作用
谁能看出我做错了什么?
最佳答案
来自文档:
$(function() { $('.item').matchHeight(); });
Will set all elements with the class item to the height of the tallest.
这意味着你必须给你的侧边栏和你的内容区域相同的类(目前它们没有共同的类)
这是 a demo它按预期工作。
关于javascript - jquery.matchHeight 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27290021/