2017-04-18 12 views
0

フレックスボックス内のアイテム間に垂直線を追加する必要があります。各項目に境界線を追加しましたが、垂直線は中央にありません。以下のコードを見つけてください。誰かが助けてくれますか?フレックスボックス内のアイテム間に等間隔の垂直線を追加

.details-wrapper { 
 
    display: flex; 
 
    justify-content: space-between; 
 
    align-items: center; 
 
    padding-top: 30px; 
 
    padding-bottom: 30px; 
 
    background-color:pink; 
 
} 
 

 
.details-wrapper div { 
 
    flex-basis: 25%; 
 
    text-align: center; 
 
    border-right: 1px solid #fff; 
 
} 
 

 
.details-wrapper span { 
 
    display: block; 
 
    margin-top: 30px; 
 
    margin-bottom: 34px; 
 
    font-size: 24px; 
 
    color: #000; 
 
} 
 

 
.details-wrapper p { 
 
    font-size: 16px; 
 
    color: #000; 
 
}
<div class="details-wrapper"> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
</div>

+0

'フレックス基準を使用し、次に、行の3つの項目が存在することになる場合:33.33パーセント;'一部左/右 'padding'有します。 –

答えて

2

あなたは速記を使用することができますflex:1;それが均等に子どもをスプレーします。それは簡単に子供を追加/削除することができます。

.details-wrapper { 
 
    display: flex; 
 
    justify-content: space-between; 
 
    align-items: center; 
 
    padding-top: 30px; 
 
    padding-bottom: 30px; 
 
    background-color: pink; 
 
    margin-bottom:3px; 
 
} 
 

 
.details-wrapper div { 
 
    flex: 1; 
 
    padding: 0.5em;/* add some padding ?*/ 
 
    text-align: center; 
 
    border-right: 1px solid #fff; 
 
} 
 

 
.details-wrapper div:last-child { 
 
    border: none; /* remove border ? */ 
 
} 
 

 
.details-wrapper span { 
 
    display: block; 
 
    margin-top: 30px; 
 
    margin-bottom: 34px; 
 
    font-size: 24px; 
 
    color: #000; 
 
} 
 

 
.details-wrapper p { 
 
    font-size: 16px; 
 
    color: #000; 
 
}
<div class="details-wrapper"> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
</div> 
 
<div class="details-wrapper"> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
</div> 
 
<div class="details-wrapper"> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
    <div> 
 
    <span>Where does it come from</span> 
 
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> 
 
    </div> 
 
</div>

+1

ほぼ完璧です。しかし、1つの小さな改善がそれをさらに良くすることができます。私の考えでは、CSS3 ':not()'セレクタの使用はより良いです。すなわち.details-wrapper div:not(:last-child){...} ' –

+0

@MohammadUsman通常、これのために、最後のものの代わりに ':first-child'を削除し、左側に境界線を設定すると、いくつかの構造体がクリアリング要素を生成するかもしれません。これは 'first-hild {border:none;}'または単に 'div + div {border-left:solid;}'でもかまいません。同じ効果のためのMnyの方法;) –

関連する問題