CSS偽對象選擇符整理

來源:互聯網
上載者:User

標籤:

1.E::selection

2.E::placeholder

 

1. E::selection

設定對象被選擇時的樣式。

需要注意的是,::selection只能定義被選擇時的background-color,color及text-shadow(IE11尚不支援定義該屬性)。

相容性:

<div class="_selection">        <p>1. Selecting master branch will publish your site from the master branch. This is useful for repositories dedicated to website content.</p>        <p>2. Selecting master branch /docs folder will publish from the /docs folder of your master branch. </p>        <p>3. This lets you maintain documentation and code together on one branch, and open source maintainers can accept contributions for both in a single pull request.</p>    </div>
._selection p::selection{    background: #eb4960;    color: #ffffff;}

預覽: 

2. E::placeholder

設定物件常值預留位置的樣式

::placeholder 虛擬元素用於控製表單輸入框預留位置的外觀,它允許開發人員/設計師改變文字預留位置的樣式,預設的文字預留位置為淺灰色。
當表單背景色為類似的顏色時它可能效果並不是很明顯,那麼就可以使用這個虛擬元素來改變文字預留位置的顏色。
需要注意的是,除了Firefox是 ::[prefix]placeholder,其他瀏覽器都是使用 ::[prefix]input-placeholder
Firefox支援該虛擬元素使用text-overflow屬性來處理溢出問題。

相容性:

程式碼範例

<div class="_placeholder">        <h1>::placeholder</h1>        <input type="text" placeholder="::placeholder的示範樣本"/>        <input type="text" placeholder="::placeholder的示範樣本"/>        <input type="text" placeholder="::placeholder的示範樣本"/>        <input type="text" placeholder="::placeholder的示範樣本"/>        <input type="text" placeholder="::placeholder的示範樣本"/>    </div>
._placeholder input {    width: 400px;    margin-bottom: 10px;}._placeholder input:nth-child(3n)::-webkit-input-placeholder { /* Google瀏覽器 */    color: #eb4960;}._placeholder input:nth-child(3n):-ms-input-placeholder { /* IE10+ */    color: #eb4960;}._placeholder input:nth-child(3n):-moz-placeholder{  /* Firefox4-18 */    color: #eb4960;}._placeholder input:nth-child(3n)::-moz-placeholder{  /* Firefox19+*/    color: #eb4960;}._placeholder input:nth-child(3n+1)::-webkit-input-placeholder { /* Google瀏覽器 */    color: #999999;}._placeholder input:nth-child(3n+1):-ms-input-placeholder { /* IE10+ */    color: #999999;}._placeholder input:nth-child(3n+1):-moz-placeholder{  /* Firefox4-18 */    color: #999999;}._placeholder input:nth-child(3n+1)::-moz-placeholder{  /* Firefox19+*/    color: #999999;}._placeholder input:nth-child(3n+2)::-webkit-input-placeholder { /* Google瀏覽器 */    color:#008aff;}._placeholder input:nth-child(3n+2):-ms-input-placeholder { /* IE10+ */    color:#008aff;}._placeholder input:nth-child(3n+2):-moz-placeholder{  /* Firefox4-18 */    color:#008aff;}._placeholder input:nth-child(3n+2)::-moz-placeholder{  /* Firefox19+*/    color:#008aff;}

效果:

 

CSS偽對象選擇符整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.