Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使两个 Div 高度保持一样 #17

Open
Tronzo opened this issue Sep 21, 2016 · 0 comments
Open

使两个 Div 高度保持一样 #17

Tronzo opened this issue Sep 21, 2016 · 0 comments

Comments

@Tronzo
Copy link
Owner

Tronzo commented Sep 21, 2016

有时你也许想让两个 div 拥有同样高度,不管它们里面有什么内容:

$('.div').css('min-height', $('.main-div').height()

该例设置了 min-height,意味着它可以比主要 div 更大,但永远不能更小。但有一个更加灵活的方法是遍历一组元素的设置,然后将高度设为元素中的最高值:

var $columns = $('.column');
var height = 0;
$columns.each(function () {
  if ($(this).height() > height) {
    height = $(this).height();
  }
});
$columns.height(height);

如果你想让所有列都有相同高度:

var $rows = $('.same-height-columns');
$rows.each(function () {
  $(this).find('.column').height($(this).height());
});
@Tronzo Tronzo changed the title 使两个 Div 高度一样 使两个 Div 高度保持一样 May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant