css上下文選取器

來源:互聯網
上載者:User
家族: 祖宗,父輩,兄弟同輩關係

1.祖先元素: 包括多級後代的元素;

2.父級元素: 僅包括一級子項目的元素;

3.相鄰元素: 擁有同一個父級的元素;

1.後代選取器:先找到祖先元素,再選擇它下面的所有指定後代元素

文法: 祖先與目標之間用空格分開,可以有多級,用多個空格區隔

格式: 祖先 目標 {聲明}

2.子選取器:先找到父級元素,再選擇他下面所有直接後代元素

文法: 父級 > 目標元素 {樣式聲明}

3.相鄰選取器: 先確定同胞元素的起始點,選擇後面的所有的指定元素

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>上下文選取器</title><style type="text/css">.art p {/*color:red;*/}.art > p {/*color: green;*/}.art h1+p {/*只會將h1後面緊鄰的p變色*//*color:blue;  */}.art p+p {clor: red;}</style></head><body><article><h1>php中文網</h1><p>永久免費的線上教學網站</p><p>將公益進行到底</p><p>為了情懷,為了夢想,為了更多像我這樣的PHP愛好者</p><section><h2>如何學習前端</h2><p>一定要多動手多寫筆記進行總結</p></section><section><h2>原來大家是這樣學習的呀~~</h2></section></article><hr><ul><li>1清單項目</li><li>2清單項目</li><li>3清單項目</li><li>4清單項目</li><li>5清單項目</li></ul></body></html>
相關文章

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.