簡體   English   中英

如何增加WordPress的內容職位的高度?

[英]How to add height for content post of wordpress?

我想使我的WordPress內容像塊一樣。 我使用CSS和PHP簡單代碼編寫了4列,並且可以正常工作。 但我希望內容也具有相同且相等的高度。

在此處輸入圖片說明

我使用了一個函數來限制內容中的字符,但帖子高度仍然不相等。

function ld_custom_excerpt_length( $length ) { return 10; } add_filter( 'excerpt_length', 'ld_custom_excerpt_length', 999 );

其實我知道我可以給他們像CSS這樣的高度

article {height:100px;} 

但是這樣做之后,內容將不再響應。

您可以使用jQuery來檢測最高的內容,並將所有元素的高度設置為最高的元素。

在這種情況下, #custom_element是我的包含所有帖子的容器。

.content是一個容器,其中包含每個帖子的我的文本,圖像等。

簡短示例:

function resizeContent() {
    jQuery('#custom_element').each(function(){  

      // Select and loop the container element of the elements you want to equalise
      var highestBox = 0;
      jQuery('.content').css("height","");

      // Select and loop the elements you want to equalise
      jQuery('.content', this).each(function(){

        // If this box is higher than the cached highest then store it
        if(jQuery(this).height() > highestBox) {
          highestBox = jQuery(this).height(); 
        }

      });  

      // Set the height of all those children to whichever was highest 
      jQuery('.content',this).height(highestBox);

    }); 
}
//adjust dimensions when loaded
jQuery(window).on('load', function () {
    resizeContent();
});
//adjust dimensions when window size gets changed
jQuery( window ).resize(function() {
    resizeContent();
});

PHP-示例:

<div id="custom_element">
    <div class="content"></div>
    <div class="content"></div>
    .
    . 
    .
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM