2017-02-21 110 views
0

我已經使用ul li列出縮略圖&文本在中心位置,但是當我們向任何li添加更多內容時,其他人正在對齊底部。ul li列表不正確對齊

使用的代碼: (加入第二鋰幾個內容,請參閱..其他李娜的位置移動到最底層,爲什麼會發生?)

.our-team ul { 
 
    width: 100%; 
 
    display: inline-block; 
 
    list-style: none; 
 
    padding: 0; 
 
    margin: 0; 
 
    text-align: center; 
 
} 
 
.our-team ul li { 
 
    display: inline-block; 
 
    padding: 0 5px; 
 
    margin-bottom: 20px; 
 
    width:25% 
 
} 
 
.our-team ul li img { 
 
    width: 100%; 
 
    max-width: 100%; 
 
    border: 4px solid #f2f2f2; 
 
} 
 
.our-team ul li section { 
 
    display: inline-block; 
 
    width: 100%; 
 
} 
 
figure { 
 
    margin: 0; 
 
    float: left; 
 
}
<div class="our-team"> 
 
    <ul class="list-6"> 
 
    <li> 
 
     <figure><img src="http://placehold.it/300x300"></figure> 
 
     <section><h3>Lorem ipsum dolor sit amet</h3> 
 
     <p>consectetur adipiscing elit</p></section> 
 
    </li> 
 
    <li> 
 
     <figure><img src="http://placehold.it/300x300"></figure> 
 
     <section><h3>sed do eiusmod tempor</h3> 
 
     <p>incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></section> 
 
    </li> 
 
    <li> 
 
     <figure><img src="http://placehold.it/300x300"></figure> 
 
     <section><h3>eiusmod tempor</h3> 
 
     <p>consectetur adipiscing elit</p></section> 
 
    </li> 
 
    </ul> 
 
</div>

+1

使用'的在垂直對齊align:top;'爲你的'.our-team ul li'使它們在使用'display:inline-block;時保持在同一級別上'' – vivekkupadhyay

回答

1

的問題是你李的不同高度的..但它們沿着基線對齊..你剛纔說vertical-align: top,他們以最快的

.our-team ul { 
 
    width: 100%; 
 
    display: inline-block; 
 
    list-style: none; 
 
    padding: 0; 
 
    margin: 0; 
 
    text-align: center; 
 
} 
 
.our-team ul li { 
 
    display: inline-block; 
 
    padding: 0 5px; 
 
    margin-bottom: 20px; 
 
    width:25%; 
 
    vertical-align: top; /* this was added in answer */ 
 
    
 
} 
 
.our-team ul li img { 
 
    width: 100%; 
 
    max-width: 100%; 
 
    border: 4px solid #f2f2f2; 
 
} 
 
.our-team ul li section { 
 
    display: inline-block; 
 
    width: 100%; 
 
} 
 
figure { 
 
    margin: 0; 
 
    float: left; 
 
}
<div class="our-team"> 
 
<ul class="list-6"> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>Lorem ipsum dolor sit amet</h3> 
 
<p>consectetur adipiscing elit</p></section> 
 
</li> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>sed do eiusmod tempor</h3> 
 
<p>incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></section> 
 
</li> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>eiusmod tempor</h3> 
 
<p>consectetur adipiscing elit</p></section> 
 
</li> 
 

 
</ul> 
 
</div>

+0

是的..它的工作......謝謝.. – Vishnu

1

試試這個你可以改變display: inline-block;flot:left;

.our-team ul { 
 
    width: 100%; 
 
    display: inline-block; 
 
    list-style: none; 
 
    padding: 0; 
 
    margin: 0; 
 
    text-align: center; 
 
} 
 
.our-team ul li { 
 
    float: left; 
 
    padding: 0 5px; 
 
    margin-bottom: 20px; 
 
    width:25% 
 
} 
 
.our-team ul li img { 
 
    width: 100%; 
 
    max-width: 100%; 
 
    border: 4px solid #f2f2f2; 
 
} 
 
.our-team ul li section { 
 
    display: inline-block; 
 
    width: 100%; 
 
} 
 
figure { 
 
    margin: 0; 
 
    float: left; 
 
}
<div class="our-team"> 
 
<ul class="list-6"> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>Lorem ipsum dolor sit amet</h3> 
 
<p>consectetur adipiscing elit</p></section> 
 
</li> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>sed do eiusmod tempor</h3> 
 
<p>incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud</p></section> 
 
</li> 
 
<li> 
 
<figure><img src="http://placehold.it/300x300"></figure> 
 
<section><h3>eiusmod tempor</h3> 
 
<p>consectetur adipiscing elit</p></section> 
 
</li> 
 

 
</ul> 
 
</div>