Get the App
SLTechnology News&Howtos  ›  Development  › 

How jQuery makes two div have the same height

Shulou Source: shulou.com Published: 2022-06-01 04:51:12 09月17日 Update

This article mainly introduces how jQuery makes the two div of the same height, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

Make the two div have the same height

Sometimes you need to make the two div have the same height no matter what they contain:

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

Set min-height, which means that it can be larger than the main div but definitely not smaller than the main div. However, a more flexible approach is to iterate through a set of elements and then set the height to the height of the highest element:

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

If you want all columns to be the same height:

Var $rows = $('.same-height-columns'); $rows.each (function () {$(this). Find (' .column'). Height ($(this). Height ();}). Thank you for reading this article carefully. I hope the article "how to make the two div height the same height" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Tags: Height same two articles elements highest value interest content at the same time meaning method more sometimes friends knowledge editing can compare industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information NVidia Shulou Tech Info Shulou Technology