1

私は e コマース製品で使用する素敵な Flexbox グリッドを取得しようとしていますが、希望どおりに動作させることができません。

ここにデモがありますhttp://jsbin.com/acejes/9/edit

無理かもしれませんが、他にできることがないか確認したかっただけです。

これが私の目的です…</p>

  1. 割合ベースのグリッドである必要があります
  2. コンテナの側面に対して最初と最後のカラム フラッシュ
  3. 最後の行が「浮き」ます

私の質問はHow to align left last row/line in multiple line flexboxに似ていますが、特に「列」に %s を使用したいのですが、それはよりきちんとしていると思います。 32.5% のような % を使用する場合は、3 列連続で言う

私はほとんどそこにいますが、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>

CSS

* {
    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%;
}
4

1 に答える 1

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>
于 2013-08-14T00:57:07.317 に答える