2016-08-21 54 views
0

正如您從附件中看到的那樣,如果第一列的文本比正確的文本更多,那麼它會導致毛刺。看附件的截圖。帶文本的自舉行故障

如何在Bootstrap中解決此問題?

enter image description here

演示: https://jsfiddle.net/oLderkuo/

/* Latest compiled and minified CSS included as External Resource*/ 
 

 
/* Optional theme */ 
 
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); 
 

 
body { 
 
    margin: 10px; 
 
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
 
<div class="container"> 
 
    
 
    <div class="portfolio-gallery row"> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. 
 
\t \t \t </span> 
 
\t \t </div> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
 
\t \t \t </span> 
 
\t \t </div> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. 
 
\t \t \t </span> 
 
\t \t </div> 
 
    
 
</div>

+1

你嘗試:文本對齊:理由; ?在你的CSS? –

+0

@NathanSchwarz我在這裏嘗試過:https://jsfiddle.net/oLderkuo/1/,但我不認爲這將解決問題。 – michaelmcgurk

+1

好吧,首先把bootdtrap放在第一位,然後按照寬度進行排序:XS - MD - LG –

回答

1

這個問題是引導應用出浮上來的同事*類 - 這意味着你的div不正確顯示 - 而不是將不必要的div添加到標記中以清除浮動 - 解決問題。

這段代碼將遍歷每個div,確定它的高度,如果它大於max-height將調整最大高度。然後它會將最大高度應用於所有div,問題將得到解決。

請注意,我已經爲此添加了調整大小的功能,並使用了aconsole .log來演示最大高度,但snipp編輯器的變幻莫測不允許最佳環境看到此操作 - 嘗試將它複製到您的自己的網頁,並嘗試在野外。它真的有用。

adjustHeight(); 
 
$(window).resize(function() { 
 
    adjustHeight(); 
 
}); 
 

 

 

 
function adjustHeight(){ 
 
    var maxHeight=0; 
 
    $('.gallery-item').each(function(){ 
 
    var height=$(this).height(); 
 
    if(height> maxHeight){maxHeight=height}; 
 
     console.log(maxHeight); 
 
    }); 
 

 
    $('.gallery-item').css('height',maxHeight+'px'); 
 
    }
/* Latest compiled and minified CSS included as External Resource*/ 
 

 
/* Optional theme */ 
 
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css'); 
 

 
body { 
 
    margin: 10px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> 
 

 
<div class="container"> 
 
    <div class="portfolio-gallery row"> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. 
 
\t \t \t </span> 
 
\t \t </div> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
 
\t \t \t </span> 
 
\t \t </div> 
 

 
\t \t <div class='gallery-item col-md-4 col-sm-6 col-xs-12'> 
 
\t \t \t <span class='sub-gallery-icon'> 
 
\t \t \t \t <a href='#' > 
 
\t \t \t \t \t <img width="300" height="200" src="http://placehold.it/300x200" class="gallery-thumb-img wp-post-image" alt="" /> 
 
\t \t \t \t </a> 
 
\t \t \t </span> 
 
\t \t \t <span class='wp-caption-text gallery-caption'><br /> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget leo leo. Sed sed pretium quam, ut bibendum libero. In semper arcu eget faucibus hendrerit. 
 
\t \t \t </span> 
 
\t \t </div> 
 
    
 
</div>

+0

感謝您抽出時間來回顧我的問題當我嘗試這個時,我得到以下內容:http://imgur.com/a/WpHU3 – michaelmcgurk

+1

嗨 - 是多數民衆贊成爲什麼我只是添加了調整大小功能,以便當您在不同的vieport大小之間移動它會調整。這是因爲功能運行的初始時間它將div設置爲340px,然後不重新計算。使用resize函數嘗試它 – gavgrif

+0

不幸的是它只在我調整視口大小時纔開始工作,在加載時它不顯示合適的值年。你知道這是爲什麼嗎? – michaelmcgurk