返回到:CSS 字体 | CSS教程
属性定义及使用说明
font-size 属性用于设置字体大小。
| 默认值: | medium |
|---|---|
| 继承: | yes |
| 版本: | CSS1 |
| JavaScript 语法: | object.style.fontSize=”larger” |
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
| 属性 | 谷歌 | IE | 火狐 | 苹果 | opera |
|---|---|---|---|---|---|
| font-size | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
看下如何设置:
/* <absolute-size>,绝对大小值 */
font-size: xx-small;
font-size: x-small;
font-size: small;
font-size: medium;
font-size: large;
font-size: x-large;
font-size: xx-large;
/* <relative-size>,相对大小值 */
font-size: larger;
font-size: smaller;
/* <length>,长度值 */
font-size: 12px;
font-size: 0.8em;
/* <percentage>,百分比值 */
font-size: 80%;
font-size: inherit;属性值
| 值 | 描述 |
|---|---|
| xx-smallx-smallsmallmediumlargex-largexx-large | 把字体的尺寸设置为不同的尺寸,从 xx-small 到 xx-large。默认值:medium。 |
| smaller | 把 font-size 设置为比父元素更小的尺寸。 |
| larger | 把 font-size 设置为比父元素更大的尺寸。 |
| length | 把 font-size 设置为一个固定的值。 |
| % | 把 font-size 设置为基于父元素的一个百分比值。 |
| inherit | 规定应该从父元素继承字体尺寸。 |
实例
设置不同的HTML元素的字体大小:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(web176.com)</title>
<style>
h1 {font-size:250%;}
h2 {font-size:200%;}
p {font-size:100%;}
</style>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<p>This is a paragraph.</p>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/cssprop/5689.html
支付宝
微信