<style>
#icons{ border: 1px solid bisque; height: 250px; } #icons .column{//每一列 width: 25%; display: inline-block; float: left; text-align: center; } #icons .column .txt{//每列文字 width: 100%; height: 52px; margin-top: 134px; border-right: 2px solid #787b83;//在此處加隔條 } #icons .column .txt:last-child{ border-right: none; } #icons .column .txt p{ width: 160px; height: 52px; font-size: 14px; line-height: 18px; color: #767777; margin-left: 25%; }
html:
<div id="icons">
<div class="column column1">
<div class="txt">
<p>打造全新世界觀,讓你更愛你的生活</p>
</div>
</div>
<div class="column column2">
<div class="txt">
<p>豐富多彩的公益活動,發揮新世界的主人公意識</p>
</div>
</div>
<div class="column column3">
<div class="txt">
<p>時尚的新理念,超前體驗未知的生活</p>
</div>
</div>
<div class="column column4">
<div class="txt">
<p>完善的培養機制,培養你全新的世界觀</p>
</div>
</div>
</div>
效果如下:

本以為在 `#icons .column .txt` 處加隔條后,想把最后一個豎隔條設為 `border:none;` 沒想到如上如所示,全部都不見了。
原來,偽類選擇器`:first-child`和`:last-child`是根據父級進行篩選的,`#icons .column .txt:last-child` 的父級是‘.txt`,在該處上的子級只有一個,最后的子級當然也是自己本身,所以要想達到效果,就應該在‘.txt`的父級添加偽類。
#icons .column:last-child .txt{ border-right: none; }
效果如下:

