如何让元素复制其他元素的自动高度CSS?

发布于 2024-12-01 01:27:39 字数 109 浏览 3 评论 0原文

我的页面上有一列具有不同的高度,设置为 height: auto;

我还有一个左侧内容部分,我想模仿右栏的高度。

我如何使用 css、jquery 或其他代码来做到这一点?

I have a right column on my page that has varying heights, set as height: auto;

I also have a left content section, that I want to mimic the height of my right column.

How can I do this using css, jquery, or some other code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冧九 2024-12-08 01:27:39
$(document).ready(function() {
    var x = $('#primary').height();
    $('#sidebar').css('height', x);
});

此 jQuery 代码片段将获取 #primary 的高度并将其应用于 #sidebar,同步两个元素的高度。

http://jsfiddle.net/pUXCE/4/ <-- 工作示例。

$(document).ready(function() {
    var x = $('#primary').height();
    $('#sidebar').css('height', x);
});

This jQuery snippet will take the height of #primary and apply it to #sidebar, syncing the height of both elements.

http://jsfiddle.net/pUXCE/4/ <-- working example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文