简体   繁体   English

将相同高度的div应用于其他div,并在调整大小时进行填充

[英]Apply same height of div to other div's with padding on resize

I have 3 divs in a div. 我的一个div中有3个div。 I want to apply same height of div to all the div who has maximum height. 我想对所有具有最大高度的div应用相同的div高度。 Not just at first time but also if screen resizes as it's responsive. 不仅是第一次,而且屏幕是否会因响应而调整大小。

Here is my html 这是我的html

<div class="mid-box-mid row"> 
                <!-- Featured Box 1 -->
                <div class="mid-box col-xs-12 col-sm-4">
                    <div class="skt-iconbox iconbox-top">       
                                <h4>Population<br><span>Health management</span></h4>
                    </div>      
                    <div class="iconbox-content">       
Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently.        
                    </div>          
                    <div class="clearfix"></div>    
                </div>
  <!-- Featured Box 3 -->
                <div class="mid-box col-xs-12 col-sm-4">
                    <div class="skt-iconbox iconbox-top">       
                                <h4>Population<br><span>Health management</span></h4>
                    </div>      
                    <div class="iconbox-content">       
Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently.        
                    </div>          
                    <div class="clearfix"></div>    
                </div>
  <!-- Featured Box 3 -->
                <div class="mid-box col-xs-12 col-sm-4">
                    <div class="skt-iconbox iconbox-top">       
                                <h4>Population<br><span>Health management</span></h4>
                    </div>      
                    <div class="iconbox-content">       
Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently.        
                      Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently.  
                    </div>          
                    <div class="clearfix"></div>    
                </div>
</div>

css CSS

.mid-box-mid{
    background-color:green;
}
.mid-box{
    background-color:red;
    padding:80px 40px;
}

javascript although right now it's static for the 3rd div's height. javascript,尽管目前对于第3个div的高度来说是静态的。

$('.mid-box-mid >div').height($('.mid-box-mid >div:nth-child(3)').height());

$( window ).resize(function() {
  $('.mid-box-mid >div').height($('.mid-box-mid >div:nth-child(3)').height());
});

Here is the FIDDLE 这是FIDDLE

you can use the .resize function. 您可以使用.resize函数。 Your code will be executed every time screen size changes and will keep your divs size syncrhonized. 每次屏幕大小更改时,将执行您的代码,并使div大小保持同步。

$( window ).resize(function() {
  $('.mid-box-mid >div').height($('.mid-box-mid >div:nth-child(3)').height());
});

please check this link to further reference: 请检查此链接以进一步参考:

jQuery resize jQuery调整大小

This is a script I used often to do exactly what you're talking about. 我经常使用此脚本来完全按照您的意思进行操作。

 // The Function jQuery.fn.equalCols = function () { $(this).css({'height' : ''}); // Array Sorter var sortNumber = function (a, b) { return b - a; }; var heights = []; // Push each height into an array $(this).each(function () { heights.push($(this).outerHeight()); }); heights.sort(sortNumber); var maxHeight = heights[0]; return this.each(function () { // Set each column to the max height $(this).css({'height': maxHeight}); }); }; //Usage jQuery(function($){ //Select the columns that need to be equal eg $('.mid-box').equalCols(); }); // Adjusts DIV size on widow Resize $(window).resize(function () { $('.mid-box').equalCols(); }); 
 .mid-box-mid{ background-color:green; } .mid-box{ background-color:red; padding:80px 40px; margin:5px 0; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="mid-box-mid row"> <!-- Featured Box 1 --> <div class="mid-box col-xs-12 col-sm-4"> <div class="skt-iconbox iconbox-top"> <h4>Population<br><span>Health management</span></h4> </div> <div class="iconbox-content"> Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently. </div> <div class="clearfix"></div> </div> <!-- Featured Box 3 --> <div class="mid-box col-xs-12 col-sm-4"> <div class="skt-iconbox iconbox-top"> <h4>Population<br><span>Health management</span></h4> </div> <div class="iconbox-content"> Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently. </div> <div class="clearfix"></div> </div> <!-- Featured Box 3 --> <div class="mid-box col-xs-12 col-sm-4"> <div class="skt-iconbox iconbox-top"> <h4>Population<br><span>Health management</span></h4> </div> <div class="iconbox-content"> Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently. Our Population Health Management helps physicians and their offices to strategically manage clinical and cost opportunities by improving overall healthcare quality of individuals care effectively and efficiently. </div> <div class="clearfix"></div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM