css 偽類:last-child等不起作用

來源:互聯網
上載者:User

標籤:


 
<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;}

 

 

 

 效果如下:

 

css 偽類:last-child等不起作用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.