CSS文本样式

2018-02-27  本文已影响0人  yangchaojun
font-family
body {
  font-family: "Gill Sans Extrabold", Helvetica, sans-serif;
}

.receipt {
  font-family: Courier, "Lucida Console", monospace;
}

浏览器如何渲染字体——字体匹配算法:
1.浏览器先获取一个系统字体列表
2.对于元素中的每一个字符,使用font-family属性及其他属性进行匹配,如果能匹配就暂定该字体
3.如果步骤2没有匹配上,选择下一个可选的font-family进行步骤2
4.如果匹配到一个字体,但是字体中没有该字符,继续对下一个可选的font-family执行步骤2
5.如果没有匹配到该字体,使用浏览器默认字体

font-size
body {
  font-size: 62.5%; /* font-size 1em = 10px */
}
p {
  font-size: 1.6em; /* 1.6em = 16px */
}
长度单位em
font-style
font-weight
line-height

字体样式不仅可以单独写,还可以写在一起

font缩写
p { font: bold 12px/14px sans-serif }
Web Fonts
@font-face {
  [ font-family: <family-name>; ] ||
  [ src: [ <url> [ format(<string>#) ]? | <font-face-name> ]#; ] ||
  [ unicode-range: <urange>#; ] ||
  [ font-variant: <font-variant>; ] ||
  [ font-feature-settings: normal | <feature-tag-value>#; ] ||
  [ font-variation-settings: normal | [ <string> <number>] # ||
 [ font-stretch: <font-stretch>; ] ||
  [ font-weight: <weight>; ] ||
  [ font-style: <style>; ]
}
<html>
<head>
  <title>Web Font Sample</title>
  <style type="text/css" media="screen, print">
    @font-face {
      font-family: "Bitstream Vera Serif Bold";
      src: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
    }
    
    body { font-family: "Bitstream Vera Serif Bold", serif }
  </style>
</head>
<body>
  This is Bitstream Vera Serif Bold.
</body>
</html>

一些字体来源


text-align
letter-spacing
word-spacing
text-indent
text-decoration
white-space
word-break
上一篇 下一篇

猜你喜欢

热点阅读