最后一行采用全宽,但我希望最后一行具有与所有其他项相同的宽度.
我附上了一个截图,说明了我的问题.
我附上了一个截图,说明了我的问题.
使用flexBox是否可行,或者我必须使用简单的CSS来满足我的要求?或者我应该使用显示表和表格单元属性?
提前致谢!
* { Box-sizing: border-Box; -moz-Box-sizing: border-Box; -webkit-Box-sizing: border-Box; } .container { width: 1170px } .listingResult { list-style: none; margin: 0px; padding: 0px; display: flex; /* NEW,Spec - Opera 12.1,Firefox 20+ */ display: -webkit-Box; /* OLD - iOS 6-,Safari 3.1-6 */ display: -moz-Box; /* OLD - Firefox 19- (buggy but mostly works) */ display: -ms-flexBox; /* TWEENER - IE 10 */ display: -webkit-flex; /* NEW - Chrome */ -webkit-flex-wrap: wrap; /* Safari 6.1+ */ flex-wrap: wrap; } .listingResult>li { width: 33.33%; -webkit-Box-flex: 1 33.33%; /* OLD - iOS 6-,Safari 3.1-6 */ -moz-Box-flex: 1 .33%; /* OLD - Firefox 19- */ -webkit-flex: 1 33.33%; /* Chrome */ -ms-flex: 1 33.33%; /* IE 10 */ flex: 1 33.33%; /* NEW,Firefox 20+ */ margin: 0 0 30px; padding: 10px; display: flex; /* NEW,Safari 3.1-6 */ display: -moz-Box; /* OLD - Firefox 19- (buggy but mostly works) */ display: -ms-flexBox; /* TWEENER - IE 10 */ display: -webkit-flex; /* NEW - Chrome */ -webkit-flex-wrap: wrap; /* Safari 6.1+ */ flex-wrap: wrap; } .listingResult>li .listingResultPic img { max-width: 100%; height: auto; } .listingResult>li .listingResultInfo { margin-top: auto; }
<div class="container"> <ul class="listingResult"> <li> <div class="listingResultPic"><img src="http://rets.906mls.com/mls_photos/1102784_1.JPG" alt="No Image" width=""></div> <div class="listingResultInfo"> <h4 class="price">$12,000</h4> <p class="address info">Co Rd AFChampion,MI 49814</p> <p class="listingNumber info">Listing Number: <a href="http://182.73.133.220/elder/listing-details/1103145">1103145</a></p> <ul class="basicInfo"> <li class="bed">3</li> <li class="bath">1</li> <li class="area">1103 sqft</li> </ul> </div> </li> <li> <div class="listingResultPic"><img src="http://rets.906mls.com/mls_photos/1102784_1.JPG" alt="No Image" width=""></div> <div class="listingResultInfo"> <h4 class="price">$12,500</h4> <p class="address info">GenevaIronwood,MI 49938</p> <p class="listingNumber info">Listing Number: <a href="http://182.73.133.220/elder/listing-details/1100143">1100143</a></p> <ul class="basicInfo"> <li class="bed">3</li> <li class="bath">2</li> <li class="area">1717 sqft</li> </ul> </div> </li> <li> <div class="listingResultPic"><img src="http://rets.906mls.com/mls_photos/1102784_1.JPG" alt="No Image" width=""></div> <div class="listingResultInfo"> <h4 class="price">$12,500</h4> <p class="address info">SaginawNorway,MI 49870</p> <p class="listingNumber info">Listing Number: <a href="http://182.73.133.220/elder/listing-details/1104097">1104097</a></p> <ul class="basicInfo"> <li class="bed">3</li> <li class="bath">1</li> <li class="area">828 sqft</li> </ul> </div> </li> <li> <div class="listingResultPic"><img src="http://rets.906mls.com/mls_photos/1102784_1.JPG" alt="No Image" width=""></div> <div class="listingResultInfo"> <h4 class="price">$12,900</h4> <p class="address info">NorthWakefield,MI 49968</p> <p class="listingNumber info">Listing Number: <a href="http://182.73.133.220/elder/listing-details/1101426">1101426</a></p> <ul class="basicInfo"> <li class="bed">3</li> <li class="bath">2</li> <li class="area">935 sqft</li> </ul> </div> </li> </ul> </div>
解决方法
将flex-grow设置为0.在列表元素上更改flex:1 33.33%to flex:0 1 33.33%.
这是您的工作代码:https://jsfiddle.net/ecgx58ep/2/
有关flex-grow:https://developer.mozilla.org/en/docs/Web/CSS/flex-grow的更多信息,请参阅此链接