使用選取器在頁面中插入內容,選取器頁面
轉載請註明文章出處:http://blog.csdn.net/lindonglian/article/details/46470455
使用選取器在頁面中插入文字
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> p:before { content: '你好,'; color: white; background-color: orange; font-family: '黑體'; } p:after { content: ',見到你很高興!'; color: white; background-color: orange; font-family: 黑體; } p.zhang:after { content: none; } p.zhang:before { content: none; } </style></head><body> <p>小紅</p> <p class="zhang">張林</p> <p>王強</p></body></html>
在標題前插入影像檔
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> h1:after { content: url(img.png); } </style></head><body> <p>王強</p></body></html>在CSS3中,使用content屬性的attr(屬性名稱)來指定attr的值。這樣可以將某個屬性的屬性值顯示出來。
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> img:after { content: attr(alt); display: block; } </style></head><body> <p align="center"> <img src="xp.png" alt="系統圖片" width="200" height="200" /> </p></body></html>添加編號
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> h3:before { content: '第'counter(count)'章'; color: red; font-family: 黑體; font-size: 24px; } h3 { counter-increment: count; } </style></head><body> <h3>HTML5簡介</h3> <h3>HTML5結構</h3> <h3>多媒體播放</h3> <h3>本機存放區</h3> <h3>表單與檔案</h3> <h3>新增元素</h3></body></html>
使用before選取器或after選取器的counter屬性,不但可以在編號中追迴文字和設定樣式,還可以為編號設定編號類型。
指定編號類型可以使用list-style-type屬性,常用的編號種類介紹如下:
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> h1:before { content: counter(count, upper-roman)'.'; color: red; font-family: 黑體; } h1 { counter-increment: count; } h2:before { content: counter(count1)'.'; color: red; font-family: 黑體; } h2 { counter-increment: count1; margin-left: 50px; } </style></head><body> <h1>建立網站及網站資訊</h1> <h2>網站建設理論</h2> <h1>安裝IIS伺服器</h1> <h2>網站管理</h2> <h1>網站欄目及版塊設計</h1> <h2>網頁文本概述</h2> <h1>設計產品資訊版塊</h1> <h2>多彩文字設計</h2></body></html>
在符號兩邊嵌入文字元號
<!DOCTYPE html><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head> <meta charset="utf-8" /> <title></title> <style type="text/css"> h1:before { content: open-quote; color: red; font-family: 黑體; } h1:after { content: close-quote; color: red; font-family: 黑體; } h1 { quotes: "《" "》"; } </style></head><body> <h1>ASP基礎教程與實驗指導</h1> <h1>電腦群組裝</h1> <h1>HTML5從新手到高手</h1></body></html>