我正在尝试使用一个很好的Flexbox网格来与电子商务产品一起使用,但却无法让它做到我想要的。
以下是演示http://jsbin.com/acejes/9/edit
这可能是不可能的,我只是想检查一下我能做些什么。
这是我的目标......
我的问题有点类似于How to align left last row/line in multiple line flexbox,但我特别想使用%s作为“列” - 我觉得它更整洁,这意味着我知道我会有,比如3列如果我使用像32.5%的%
那么一行我差不多了,但是由于justify-content属性,最后一行被抛出了。我想最后一行是“浮动”的:
在上面的jsbin中查看我的代码更容易,但为了保存,这里有一个小快照:
<div id="flexbox">
<div class="column">
<img src="http://placehold.it/350x150" title="" alt="" />
</div>
<div class="column">
<p class="product-title">Decorated Pink High Heels</p>
<p class="product-price">$25.99</p>
<p class="product-title">Decorated Pink High Heels</p>
</div>
</div>
* {
box-sizing: border-box;
}
#flexbox {
display: flex;
flex-flow: row wrap;
width: 100%;
justify-content: space-between;
border: 3px solid black;
}
#flexbox .column {
width: 22%;
margin-bottom: 30px;
background-color: red;
}
img {
max-width: 100%;
}
答案 0 :(得分:0)
我不认为使用Flexbox可以实现这个确切的解决方案,但您可以使用高级选择器,而不是像http://jsbin.com/acejes/14/edit
<div class="l-col_33--all">
<div class="l-col l-col_33">
<div class="l-col l-col_50">
<img src="http://placehold.it/350x150" title="" alt="" />
</div>
<div class="l-col l-col_50">
<p class="product-title">1st product Decorated Pink High Heels</p>
<p class="product-price">$25.99</p>
<p class="product-title">Decorated Pink High Heels</p>
</div>
</div>
<div class="l-col l-col_33">
<div class="l-col l-col_100">
<img src="http://placehold.it/350x150" title="" alt="" />
</div>
<div class="l-col l-col_100">
<p class="product-title">2nd product Decorated Pink High Heels</p>
<p class="product-price">$25.99</p>
</div>
</div>
<div class="l-col l-col_33">
<div class="l-col l-col_50">
<img src="http://placehold.it/350x150" title="" alt="" />
</div>
<div class="l-col l-col_50">
<p class="product-title">3rd product Decorated Pink High Heels</p>
<p class="product-price">$25.99</p>
</div>
</div>
</div>
<style>
img {
max-width: 100%;
}
body {
border: 1px solid black;
}
p {
padding-right: 10px;
padding-left: 10px;
}
/* E.g. Use an "--all" modifier class on a div wrapper to flush columns against their container */
.l-col_33--all .l-col_33 {
width: 32%;
margin-bottom: 40px;
background-color: red;
}
.l-col_33--all .l-col_33:nth-child(1),
.l-col_33--all .l-col_33:nth-child(3n+1) {
margin-right: 2%;
border-bottom: 3px solid green;
}
.l-col_33--all .l-col_33:nth-child(3),
.l-col_33--all .l-col_33:nth-child(3n) {
margin-left: 2%;
border-bottom: 3px solid blue;
}
/* Clear rows */
.l-col_33--all .l-col_33:nth-child(3n+1) {
clear: left;
}
.l-col_33--all:after { /* clearfix */
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.l-col {
position: relative;
float: left;
}
.l-col_33 {
width: 33%;
}
</style>