2015-09-25 74 views
0

如何在列表視圖項中垂直居中文本?jQuery移動中間垂直對齊在列表視圖中

例如,運行此代碼:

<ul data-role="listview" id="exerciseList">  
<li> 
    <img src="http://upload.wikimedia.org/wikipedia/pt/0/02/Homer_Simpson_2006.png"> 
    <p>Some large text 
    Some large text 
    Some large text 
    Some large text 
    Some large text 
    Some large text</p> 
</li> 
</ul> 

我得到這個:

enter image description here

但我需要這樣的:

enter image description here

+0

嘗試使用flex佈局。使用flexbox佈局顯示,您可以在容器內排列垂直和水平佈局元素。此鏈接可能很有用https://css-tricks.com/snippets/css/a-guide-to-flexbox/ – Ravish

+0

我訪問了提供的鏈接,但不知道如何處理這些信息,有人請提供更直接的解決方案? – rettiseert

回答

0

我認爲這是可以使用彈性盒很容易完成。我把你的代碼,並創建了一個code pen,我把這裏和那裏添加一些元素,例如自由:

HTML

<div class="slide-show"> 
    <ul data-role="listview" id="exerciseList"> 
    <li> 
     <div class="image"> 
     <img src="http://upload.wikimedia.org/wikipedia/pt/0/02/Homer_Simpson_2006.png"> 
     </div> 
     <div class="detail"> 
     Some large text Some large text Some large text Some large text Some large text Some large text 
     </div> 
    </li> 
    </ul> 
</div> 

CSS

.slide-show { 
    border: 1px dashed black; 
    display: flex; 
    display: -webkit-flex; 
    flex-direction: row; 
    -webkit-flex-direction: row; 
    align-items: center; 
    -webkit-align-items: center; 
} 
.slide-show ul { 
    list-style-type: none; 
} 

#exerciseList li { 
    align-items: center; 
    display: flex; 
    flex-direction: row; 
    list-style-type: none; 
    width: 100%; 
} 

#exerciseList li .image { 
    margin-right: 20px; 
} 
#exerciseList li .image img { 
    height: 100px; 
} 

有無看看code pen並親自看看,你可以使用上面提供的鏈接爲你自己定製它

+0

提供的示例看起來不錯,但是,當我嘗試將CS​​S應用於jQuery移動listview時,我無法獲得預期的結果。我該如何將相同的想法應用於jQuery移動列表視圖? – rettiseert

+0

我從來沒有使用jQuery Mobile,所以不能多說。但是,我確實發現這個線程是論壇https://forum.jquery.com/topic/tabular-listviews-using-the-flexbox-model這沒有答案,但是,似乎他正在試圖做你想做的事情至。我相信你需要稍微調整一下結果,具體取決於你的html結構和CSS。 – Ravish