查看: 748|回复: 0
上一主题 下一主题

从零学CSS系列之文本属性

79186

主题

0

好友

积分

离线 发信

跳转到指定楼层
楼主
发表于 2017-03-10 21:49 | 只看该作者 | 倒序浏览

1.line-height

互缁涓绱瀹涓涓甯﹀浣缂╂惧瀛锛杩峰浠e绱灏变缁ф胯涓缉惧瀛锛规韩瀛峰ぇ灏ヨ绠繁琛楂(line-height)硷

浠g濡涓:
body {
  font-size: 12px;
  line-height: 1.5;
}

h1 {
  font-size: 36px;
}

杩锛body line-height 18px锛12 * 1.5锛锛 h1 line-height 54px锛36 * 1.5锛

灏辩浣跨 em锛惧姣绛稿浣锛浠e绱缁ф跨浠舵绠琛楂(line-height)硷姣濡涓㈢ body 琛楂规 1.5em锛d h1 琛楂灏变缁ф胯涓 18px

2.text-decoration

慨楗版缁ф跨被灞э缁 body 绱璁剧疆涓 none锛骞朵浼褰卞板浠d腑榛璁ゆ慨楗扮绱锛渚濡瓒炬ワ浠ュ瑕绘瓒炬ョ榛璁や绾胯瑕琛璁剧疆锛

浠g濡涓:


a {
  text-decoration: none;
}

界惰灞ч璁や缁ф匡浣绱涓璁剧疆淇グ浼寤朵几板浠e绱涓

浠g濡涓:


<p>涓绾 <span>浼涓绾垮</span></p>

浠g濡涓:
p {
  color: red;
  text-decoration: underline;
}

p span {
  color: green;
  text-decoration: none;
}

杩涓绾挎 p 绱

浠g濡涓:
p {
  color: red;
  text-decoration: underline;
}

p span {
  color: green;
  text-decoration: underline;
}

变慨楗板х寤朵几浼涓浜煎х锛浠/P>

濂界娉灏辨瑕淇グ缃 text-decoration 灞с

3.text-indent

互浣跨ㄨ灞х姣涓介琛缂╄2涓绗︼涓娇ㄧ┖硷

浠g濡涓:


p {
  text-indent: 2em;
}

涔互瀹涓涓扮硷浜х棣琛锛

璁╁锋涔绉甯哥ㄥ娉锛

璁╂缉杩颁涓冻澶杩版癸互璁╂瀛娑澶憋

浠g濡涓:


text-indent: -9999px;

 姝わ甯哥惧挎㈡瀛甯哥ㄦ规锛

浠g濡涓:


.logo {
  background: url(logo.png) no-repeat;
  display: inline-block;
  height: 36px;
  text-indent: -9999px;
  width: 72px;
}

IE6/7 骞朵姝f inline-block锛浜典戒瀵艰 .logo 娑澶变瑙锛互浣跨ㄦ诞ㄦ block 夸唬 inline-block锛涓杩涓よ戒瑰甯灞瑰锛涔互浣跨ㄥ跺规

4.text-overflow

甯告典锛夸覆URL板锛ㄨ哄ㄦ朵婧㈠猴浠互璁惧褰孩哄ㄦ舵剧ずョ凤

浠g濡涓:


li {
  overflow: hidden;
  text-overflow: ellipsis;
}


蹇椤婚 overflow: hidden; 涓璧蜂娇跺借寰涓涓涓搴︼姣濡IE 6锛

瀵逛d榛璁ゆ典骞朵浼婧㈠虹瑕寮哄跺跺ㄤ琛剧ず锛杩锋戒骇锛

浠g濡涓:


li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%; /* for IE 6 */
}

浣跨 white-space: pre; word-break: keep-all; 涔藉己舵ㄤ琛剧ず锛涓杩

IE 8/9 涓跺浼版病锛f芥绱涓涓绱璁剧疆浜word-wrap: break-word; 璇ュт琛ㄧ板姣 white-space: nowrap; 村己匡浠ワ跺杩寰涓涓唬锛

浠g濡涓:


word-wrap: normal;

5.text-shadow

ㄩ借茶娣辫叉瀛涓锛互瀹版浜宓锛

浠g濡涓:


text-shadow: 0 1px 0 rgba(255,255,255,.75);

互缁坊澶涓村奖锛ㄩ峰锛

浠g濡涓:


text-shadow: 0 1px 0 #fff, 0 2px 0 #ddd, 0 3px 0 #ddd, 0 4px 0 #ddd;

6.white-space

white-space 灞ц缃浣澶绱绌虹姐

璁剧疆间负 nowrap 璁╂互ㄥ涓琛涓缁х画锛拌竟涔涓浼㈣锛村伴 <br> 绛撅

浠g濡涓:


white-space: nowrap;

舵浠淇腑绌烘煎㈣绗︿绫荤锛姣濡灞绀鸿绠虹婧浠g跺锛灏变ㄥ <pre>锛 <pre> white-space 灞х煎氨 pre锛

浠g濡涓:


pre {
  white-space: pre;
}

pre 涔涓d灏藉浜烘锛拌竟跺涓浼ㄦ㈣锛浠 CSS 2.1 板浜 pre-wrap锛

浠g濡涓:


pre {
  white-space: pre;
  white-space: pre-wrap;
}

杩 pre 绱瀹规㈣戒煎锛藉ㄥ瀹硅鸿竟跺ㄦ㈣

变涓娴瑙ㄩ芥 pre-wrap锛浠ヨ瑕璁╅d涓娴瑙ㄥ己舵㈣锛

浠g濡涓:


pre {
  white-space: pre;
  white-space: pre-wrap;
  word-wrap: break-word;
}

褰讹涔璁镐骞朵甯㈣锛涔涓浠姘村钩婊ㄦ★e互ㄦ按骞虫ㄦ℃ヤ唬挎㈣锛

浠g濡涓:


pre {
  overflow: auto;
}

7.word-break

webkit 澶у锛 Google Chrome锛Safari锛Android Browser 绛绛锛涓 keep-all 硷浠ヨ界ㄧ涔灏 break-all 浜锛

浠g濡涓:


word-break: break-all;

涓杩浼辨璇婚纰锛搴璇ユ

8.word-wrap

杩 word-break 村ソ瀹版㈣瑰锛

浠g濡涓:


word-wrap: break-word;

娣诲涓涓孩洪锛垮涓浜舵杩缁绗︼

浠g濡涓:


overflow: hidden;

来源:http://www.jb51.net/article/50248.htm