css中虛擬元素的使用方法小結(代碼)

來源:互聯網
上載者:User

本篇文章給大家帶來的內容是關於css中虛擬元素的使用方法小結(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

把文本的第一個字母設為特殊的字母

<!DOCTYPE html ><html><head><meta charset="utf-8"> <title>自學教程(如約智惠.com)</title> <style >p:first-letter {color:#ff0000;font-size:xx-large;}</style></head><body><p>你可以使用"first-letter"虛擬元素向文本的首字母設定特殊樣式;</p></body></html>

把第一行文字設定為特殊

<!DOCTYPE html ><html><head><meta charset="utf-8"> <title>自學教程(如約智惠.com)</title> <style >p:first-letter {color:#ff0000;font-size:xx-large;}</style></head><body><p>你可以使用"first-letter"虛擬元素向文本的首字母設定特殊樣式;</p></body></html>

把第一行文字的第一個字母設定為特殊

<!DOCTYPE html ><html><head><meta charset="utf-8"> <title>自學教程(如約智惠.com)</title> <style >p:first-letter{color:#ff0000;font-size:xx-large;}p:first-line {color:#0000ff;font-variant:small-caps;}</style></head><body><p>你可以結合使用"first-line"和"first-letter"虛擬元素向文本的首行和首字母設定特殊樣式。</p></body></html>

使用:在一個元素之前插入一些內容

<!DOCTYPE html ><html><head><meta charset="utf-8"> <title>自學教程(如約智惠.com)</title> <style >h1:before {content:url(smiley.gif);}</style></head><body><h1>This is a heading</h1><p>The :before pseudo-element inserts content before an element.</p><h1>This is a heading</h1><p><b>注意:</b>僅當 !DOCTYPE 已經聲明 IE8 支援這個內容屬性</p></body></html>

使用:在一個元素之後插入一些內容

<!DOCTYPE html ><html><head><meta charset="utf-8"> <title>自學教程(如約智惠.com)</title> <style >h1:after {content:url(smiley.gif);}</style></head><body><h1>This is a heading</h1><p>The :before pseudo-element inserts content before an element.</p><h1>This is a heading</h1><p><b>注意:</b>僅當 !DOCTYPE 已經聲明 IE8 支援這個內容屬性</p></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.