篇文章主要講述了CSS樣式更改中的背景Background,這篇文章我們來談?wù)勎谋綜ontent內(nèi)容的基礎(chǔ)用法
1)).首行縮進(jìn)文本
<div style='text-indent:2em'></div> 可以設(shè)置負(fù)數(shù) 也可使用百分?jǐn)?shù) 像素
2)).文本對(duì)齊方式
<div style='text-align:center'></div>
left 左邊
right 右邊
center 中間
justify 兩端對(duì)齊
3)).字間距
<div style='word-spacing:2em'></div> 可以設(shè)置負(fù)數(shù) 也可使用百分?jǐn)?shù) 像素
4)).文本間距
<div style='letter-spacing:2em'></div> 可以設(shè)置負(fù)數(shù) 也可使用百分?jǐn)?shù) 像素
5)).文本轉(zhuǎn)換
<div style='text-transform:none'></div>
none 不轉(zhuǎn)換
uppercase 大寫
lowercase 小寫
capitalize 首字母大寫
6)).文本修飾
<div style='text-decoration:none'></div>
none 不修飾
underline 下劃線
overline 上劃線
line-through 中劃線
blink 文本閃爍
7)).文本空白符的處理
<div style='white-space:normal'></div>
pre-line 合并空白符序列,但是保留換行符
normal 忽略空白符
nowrap 文本不會(huì)換行,直到<br>出現(xiàn)才換行
pre 空白會(huì)被瀏覽器保留
pre-wrap 保留空白符序列,但是正常地進(jìn)行換行
8)).文本方向
<div style='direction:ltr'></div>
ltr 從左到右
rtl 從右到左
9)).文本行高
<div style='line-height:2'></div> 可使用百分?jǐn)?shù) 像素
10)).文本陰影
<div style='text-shadow:1px 1px 1px red'></div>
11)).字符換行
<div style='word-wrap:normal'></div>
normal 只在允許的斷字點(diǎn)換行
break-word 在長單詞、URL地址內(nèi)部進(jìn)行換行
12)).處理溢出文本
<div style='text-overflow:ellipsis'></div>
clip 修剪文本
ellipsis 省略符號(hào)來代表被修剪的文本
string 使用給定的字符串來代表被修剪的文本
13)).文本輪廓
<div style='text-outline:1px 1px red'></div>
14)).文本換行
<div style='text-wrap:none'></div>
normal 只在允許的換行點(diǎn)進(jìn)行換行。
none 不換行。元素?zé)o法容納的文本會(huì)溢出
unrestricted 在任意兩個(gè)字符間換行。
suppress 壓縮元素中的換行。瀏覽器只在行中沒有其它有效換行點(diǎn)時(shí)進(jìn)行換行。
這篇文章主要介紹了CSS樣式更改篇中的文本Content基本設(shè)置,希望讓大家對(duì)CSS選擇器有個(gè)簡單的認(rèn)識(shí)和了解。
****看完本文有收獲?請(qǐng)轉(zhuǎn)發(fā)分享給更多的人****
IT共享之家
入群請(qǐng)?jiān)谖⑿藕笈_(tái)回復(fù)【入群】
想要學(xué)習(xí)更多,請(qǐng)前往Python爬蟲與數(shù)據(jù)挖掘?qū)S镁W(wǎng)站:http://pdcfighting.com/
來看下常用的標(biāo)簽列表,后文會(huì)一一介紹:
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區(qū)分大小寫 -->
<html lang="zh-cmn-Hans"> <!-- 更加標(biāo)準(zhǔn)的 lang 屬性寫法 http://zhi.hu/XyIa -->
<head>
<meta charset='utf-8'> <!-- 聲明文檔使用的字符編碼 -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 優(yōu)先使用 IE 最新版本和 Chrome -->
<meta name="description" content="不超過150個(gè)字符" /> <!-- 頁面描述 -->
<meta name="keywords" content=""/> <!-- 頁面關(guān)鍵詞 -->
<meta name="author" content="name, email@gmail.com" /> <!-- 網(wǎng)頁作者 -->
<meta name="robots" content="index,follow" /> <!-- 搜索引擎抓取 -->
<!-- 為移動(dòng)設(shè)備添加 viewport -->
<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"> <!-- `width=device-width` 會(huì)導(dǎo)致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時(shí)出現(xiàn)黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->
<!-- iOS 設(shè)備 begin -->
<meta name="apple-mobile-web-app-title" content="標(biāo)題"> <!-- 添加到主屏后的標(biāo)題(iOS 6 新增) -->
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否啟用 WebApp 全屏模式 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 設(shè)置狀態(tài)欄的背景顏色,只有在 `"apple-mobile-web-app-capable" content="yes"` 時(shí)生效 -->
<meta name="format-detection" content="telephone=no" /> <!-- 禁止數(shù)字識(shí)自動(dòng)別為電話號(hào)碼 -->
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) -->
<!-- iOS 圖標(biāo) begin -->
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone 和 iTouch,默認(rèn) 57x57 像素,必須有 -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad,144x144 像素,可以沒有,但推薦有 -->
<!-- iOS 圖標(biāo) end -->
<!-- iOS 啟動(dòng)畫面 begin -->
<link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad 豎屏 768 x 1004(標(biāo)準(zhǔn)分辨率) -->
<link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad 豎屏 1536x2008(Retina) -->
<link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad 橫屏 1024x748(標(biāo)準(zhǔn)分辨率) -->
<link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad 橫屏 2048x1496(Retina) -->
<link rel="apple-touch-startup-image" href="/splash-screen-320x480.png" /> <!-- iPhone/iPod Touch 豎屏 320x480 (標(biāo)準(zhǔn)分辨率) -->
<link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch 豎屏 640x960 (Retina) -->
<link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) -->
<!-- iOS 啟動(dòng)畫面 end -->
<!-- iOS 設(shè)備 end -->
<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼顏色 -->
<meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁貼圖標(biāo) -->
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 -->
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- 添加 favicon icon -->
<title>標(biāo)題</title>
</head>
基本標(biāo)簽
使用 HTML5 doctype,不區(qū)分大小寫。
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不區(qū)分大小寫 -->
聲明文檔使用的字符編碼
<meta charset='utf-8'> <!-- 聲明文檔使用的字符編碼 -->
更加標(biāo)準(zhǔn)的 lang 屬性寫法 http://zhi.hu/XyIa
很少情況才需要加地區(qū)代碼,通常是為了強(qiáng)調(diào)不同地區(qū)漢語使用差異,例如:
<p lang="zh-cmn-Hans">
<strong lang="zh-cmn-Hans-CN">菠蘿</strong>和<strong lang="zh-cmn-Hant-TW">鳳梨</strong>其實(shí)是同一種水果。只是大陸和臺(tái)灣稱謂不同,且新加坡、馬來西亞一帶的稱謂也是不同的,稱之為<strong lang="zh-cmn-Hans-SG">黃梨</strong>。
</p>
優(yōu)先使用 IE 最新版本和 Chrome
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <!-- 優(yōu)先使用 IE 最新版本和 Chrome -->
SEO 優(yōu)化
頁面描述
每個(gè)網(wǎng)頁都應(yīng)有一個(gè)不超過 150 個(gè)字符且能準(zhǔn)確反映網(wǎng)頁內(nèi)容的描述標(biāo)簽。文檔
<meta name="description" content="不超過150個(gè)字符" /> <!-- 頁面描述 -->
頁面關(guān)鍵詞
<meta name="keywords" content=""/> <!-- 頁面關(guān)鍵詞 -->
定義頁面標(biāo)題
<title>標(biāo)題</title>
定義網(wǎng)頁作者
<meta name="author" content="name, email@gmail.com" /> <!-- 網(wǎng)頁作者 -->
定義網(wǎng)頁搜索引擎索引方式,robotterms是一組使用英文逗號(hào)「,」分割的值,通常有如下幾種取值:none,noindex,nofollow,all,index和follow。文檔
<meta name="robots" content="index,follow" /> <!-- 搜索引擎抓取 -->
可選標(biāo)簽
為移動(dòng)設(shè)備添加 viewport
<meta name="viewport" content="initial-scale=1, maximum-scale=3, minimum-scale=1, user-scalable=no"> <!-- `width=device-width` 會(huì)導(dǎo)致 iPhone 5 添加到主屏后以 WebApp 全屏模式打開頁面時(shí)出現(xiàn)黑邊 http://bigc.at/ios-webapp-viewport-meta.orz -->
content 參數(shù):
iOS 設(shè)備
添加到主屏后的標(biāo)題(iOS 6 新增)
<meta name="apple-mobile-web-app-title" content="標(biāo)題"> <!-- 添加到主屏后的標(biāo)題(iOS 6 新增) -->
是否啟用 WebApp 全屏模式
<meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否啟用 WebApp 全屏模式 -->
設(shè)置狀態(tài)欄的背景顏色
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 設(shè)置狀態(tài)欄的背景顏色,只有在 `"apple-mobile-web-app-capable" content="yes"` 時(shí)生效 -->
content 參數(shù):
如果設(shè)置為 default 或 black ,網(wǎng)頁內(nèi)容從狀態(tài)欄底部開始。
如果設(shè)置為 black-translucent ,網(wǎng)頁內(nèi)容充滿整個(gè)屏幕,頂部會(huì)被狀態(tài)欄遮擋。
禁止數(shù)字識(shí)自動(dòng)別為電話號(hào)碼
<meta name="format-detection" content="telephone=no" /> <!-- 禁止數(shù)字識(shí)自動(dòng)別為電話號(hào)碼 -->
iOS 圖標(biāo)
rel 參數(shù):
apple-touch-icon 圖片自動(dòng)處理成圓角和高光等效果。
apple-touch-icon-precomposed 禁止系統(tǒng)自動(dòng)添加效果,直接顯示設(shè)計(jì)原圖。
iPhone 和 iTouch,默認(rèn) 57x57 像素,必須有
<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone 和 iTouch,默認(rèn) 57x57 像素,必須有 -->
iPad,72x72 像素,可以沒有,但推薦有
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png" /> <!-- iPad,72x72 像素,可以沒有,但推薦有 -->
Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以沒有,但推薦有 -->
Retina iPad,144x144 像素,可以沒有,但推薦有
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad,144x144 像素,可以沒有,但推薦有 -->
iOS 啟動(dòng)畫面
官方文檔:https://developer.apple.com/library/ios/qa/qa1686/_index.html
參考文章:http://wxd.ctrip.com/blog/2013/09/ios7-hig-24/
iPad 的啟動(dòng)畫面是不包括狀態(tài)欄區(qū)域的。
iPad 豎屏 768 x 1004(標(biāo)準(zhǔn)分辨率)
<link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad 豎屏 768 x 1004(標(biāo)準(zhǔn)分辨率) -->
iPad 豎屏 1536x2008(Retina)
<link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad 豎屏 1536x2008(Retina) -->
iPad 橫屏 1024x748(標(biāo)準(zhǔn)分辨率)
<link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad 橫屏 1024x748(標(biāo)準(zhǔn)分辨率) -->
iPad 橫屏 2048x1496(Retina)
<link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad 橫屏 2048x1496(Retina) -->
iPhone 和 iPod touch 的啟動(dòng)畫面是包含狀態(tài)欄區(qū)域的。
iPhone/iPod Touch 豎屏 320x480 (標(biāo)準(zhǔn)分辨率)
<link rel="apple-touch-startup-image" href="/splash-screen-320x480.png" /> <!-- iPhone/iPod Touch 豎屏 320x480 (標(biāo)準(zhǔn)分辨率) -->
iPhone/iPod Touch 豎屏 640x960 (Retina)
<link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch 豎屏 640x960 (Retina) -->
iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina)
<link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 豎屏 640x1136 (Retina) -->
添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari)文檔
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- 添加智能 App 廣告條 Smart App Banner(iOS 6+ Safari) -->
Android
Android Lollipop 中的 Chrome 39 增加 theme-color meta 標(biāo)簽,用來控制選項(xiàng)卡顏色。
http://updates.html5rocks.com/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
<meta name="theme-color" content="#db5945">
Windows 8
Windows 8 磁貼顏色
<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁貼顏色 -->
Windows 8 磁貼圖標(biāo)
<meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁貼圖標(biāo) -->
其他
添加 RSS 訂閱
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 訂閱 -->
添加 favicon icon
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- 添加 favicon icon -->
禁止 Chrome 瀏覽器中自動(dòng)提示翻譯
content和attr屬性用的不是很多,但是它們能在頁面下面悄悄的使用CSS來生成內(nèi)容,下面讓我們看看content和attr的用法相互配合產(chǎn)生神奇效果的
基本content用法
content屬性能讓程序員使用CSS往頁面元素里填寫內(nèi)容:
.myDiv:after { content: "我是一個(gè)使用*content*屬性生產(chǎn)的靜態(tài)文字"; }
注意,如果想讓偽元素:after絕對(duì)定位,必須對(duì)div設(shè)置position:relative
content和attr配合使用
content使用attr來從頁面元素中動(dòng)態(tài)的獲取內(nèi)容:
attr屬性通常和自定義屬性data-配合使用,因?yàn)閭鹘y(tǒng)的其它屬性雖然也能存值,但通常不適合存放表達(dá)性文字。
content里的字符串連接操作
還需要用JS里的字符串嗎?答案是不需要了,CSS3里就能完成這些,是不是很神奇!attr的動(dòng)態(tài)生成頁面內(nèi)容的能力著實(shí)是一件讓人興奮的事情。實(shí)際上可以用它配合content對(duì)頁面的很多其他元素和屬性進(jìn)行操作。
切版 qieban(.cn)
*請(qǐng)認(rèn)真填寫需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。