2017-04-18 34 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

幾乎完美。然而,一個小的改進可以使它更好。而不是重寫最後一項的CSS,在我看來,使用CSS3':not()'選擇器更好,也就是'.details-wrapper div:not(:last-child){...}' –

+0

@MohammadUsman通常,爲此,你(我)選擇':first-child'來代替最後一個,並將邊界設置在左邊,某些結構可能會產生一個清除元素。它可以是'first-hild {border:none;}'或者甚至簡單地'div + div {border-left:solid;}'。多少種方式可以達到同樣的效果;) –